How do you get the index of the current iteration of a foreach loop?
Ian Mercer posted a similar solution as this on Phil Haack’s blog: This gets you the item (item.value) and its index (item.i) by using this overload of LINQ’s Select: the second parameter of the function [inside Select] represents the index of the source element. The new { i, value } is creating a new anonymous object. Heap allocations can be avoided … Read more