Tip: getting the index in a foreeach statement

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


Thu Dec 10 2009 01:44:00 GMT-0800 (Pacific Standard Time)


Next page: Making a bootable Windows 7 USB Memory Stick

Previous page: Future proof your home with a new conduit system?