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: foreach (var item in Model.Select((value, i) => new { i, value })) { var value = item.value; var index = item.i; } This gets you the item (item.value) and its index (item.i) by using this overload of LINQ’s Select: the second parameter of … Read more