It’s interesting a clearer, shorter and more compact solution than

IEnumerator<T> GetEvens<T>(List<T> list) { for (int i = 1; i < list.Count; i += 2) { yield return list[i] } } 
  • If the number is divisible by two (the remainder of the division is zero) then this is an even element, otherwise it is an odd one. - Comfmore 1:01 pm
  • Surely you can be more compact with Linq - Vladimir Gordeev

1 answer 1

Using LINQ:

 var evens = list.Where((x, i) => (i % nStep) == 1);