使用linq查找列表中特定项的索引

我有一个从1到20的整数列表。我想要使用linq大于10的项目索引。 是否可以使用linq?

提前致谢

使用包含索引的Select的重载:

 var highIndexes = list.Select((value, index) => new { value, index }) .Where(z => z.value > 10) .Select(z => z.index); 

这些步骤依次为:

  • 将值序列投影到值/索引对序列中
  • 过滤为仅包含值大于10的对
  • 将结果投影到一系列索引
  public static List FindIndexAll(this List src, Predicate value) { List res = new List(); var idx = src.FindIndex(x=>x>10); if (idx!=-1) { res.Add(idx); while (true) { idx = src.FindIndex(idx+1, x => x > 10); if (idx == -1) break; res.Add(idx); } } return res; } 

用法

  List test= new List() {1,10,5,2334,34,45,4,4,11}; var t = test.FindIndexAll(x => x > 10);