在 C# 中使用 lambda 或 linq 查找项目索引

Find item index with lambda or linkq in c#

嗨,我不会说英语,如果我让你感到困惑,请原谅我。

在 c# 中我有 3 个 String List.

list_one: 文件地址列表。

list_two:用list_one.

生成的MD5列表

list_three:用 list_two 生成的 MD5 列表,但在这个列表中我从 [=42= 收集了重复项]

问题:

如何获取 list_three 中的每个项目并在 list_two 中搜索,然后 return 该索引。

但我不喜欢使用 for 或 foreach,因为那会减慢我的应用程序。

如何使用 linq 或 lambda 或任何最快的方式做到这一点。

my lists Image

No 1 foeach 并不慢。但是要回答你想要的是这样简单的一个班轮。

using System.Linq;  

List<string> list = new List<string>{"a","b","c","d"};
List<string> list2 = new List<string>{"a","c"};  

var result = list.Select((a, b) => new {Value = a, Index = b})
              .Where(x => list2.Any(d => d == x.Value))
              .Select(c => c.Index).ToArray();

现在 result 包含所有匹配索引。Fiddle