Home > Software engineering >  How to get the even item positions in a list with LINQ
How to get the even item positions in a list with LINQ

Time:06-18

I have a list like this

List<double> points1 = new List<double>
{
  10, 20, 30, 40, 50, 60, 70, 80, 90, 100
};

How can I get the even positions with LINQ in order to get a list like this

20,40,60,80,100

I know how to do it with a for loop, but I want this in a single line with LINQ

CodePudding user response:

points1.Where((value, idx) => idx % 2 != 0);
  • Related