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
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;
}
Usage
List test= new List() {1,10,5,2334,34,45,4,4,11};
var t = test.FindIndexAll(x => x > 10);