Reputation: 21280
How I can select using Linq only entries from even positions in a list ?
Upvotes: 5
Views: 263
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