Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 remove 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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading