Find indices of particular items in the list using linq
c#, linq
Solution
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);
The steps in turn:
- Project the sequence of values into a sequence of value/index pairs
- Filter to only include pairs where the value is greater than 10
- Project the result to a sequence of indexes
Problem
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? Thanks in advance