Using LINQ you can easily get at the index in a foreach statement.
List x = new List() {"a", "b", "c"}; var augmented = x.Select((item, index) => new { item = s, index = index }); foreach (var d in augmented) { Console.WriteLine(d.item + " " + d.index); } Console.ReadKey(); a 0 b 1 c 2
The post Tip: getting the index in a foreeach statement appeared first on Ian Mercer.