Night Walker
Night Walker

Reputation: 21280

How can I take only entries from even positions in List

How I can select using Linq only entries from even positions in a list ?

Upvotes: 5

Views: 263

Answers (1)

goric
goric

Reputation: 11905

You can use the overload to Enumerable.Where in which the predicate includes the item's index.

var myList = new List<int>{ 1, 2, 3, 4, 5, 6 };
var evenIndexes = myList.Where( (num, index) => index % 2 == 0);

Upvotes: 9

Related Questions