Mario
Mario

Reputation: 14800

How to get the even item positions in a list with LINQ

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

Upvotes: 0

Views: 198

Answers (1)

Pavel Ajtkulov
Pavel Ajtkulov

Reputation: 521

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

Upvotes: 3

Related Questions