查找使用列表中特定项目的指标LINQ [英] Find indices of particular items in the list using linq
本文介绍了查找使用列表中特定项目的指标LINQ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有整数从1到20的一览我想这是大于10使用LINQ项的索引。是否有可能使用LINQ办?
I have a list of integers from 1 to 20. I want the indices of items which are greater than 10 using linq. Is it possible to do with linq?
在此先感谢
推荐答案
使用选择
,其中包括索引的过载:
Use the overload of Select
which includes the index:
var highIndexes = list.Select((value, index) => new { value, index })
.Where(z => z.value > 10)
.Select(z => z.index);
依次的步骤:
- 项目值的序列转化为价值/指数对的序列
- 过滤器只包括对其中的值大于10
- 项目的结果索引的顺序
这篇关于查找使用列表中特定项目的指标LINQ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文