Skip to content

Instantly share code, notes, and snippets.

@keithbloom
Created February 25, 2011 13:59
Show Gist options
  • Save keithbloom/843816 to your computer and use it in GitHub Desktop.
Save keithbloom/843816 to your computer and use it in GitHub Desktop.
LINQ Select query which includes the iterator index in the projection
var lines = new[]
{
"Line1", "Line2", "Line3"
};
var query = lines.Select((line, index) => new
{
Prop = string.Format("Address{0}", index + 1),
Value = line
});
foreach (var prop in query)
{
Console.WriteLine("{0} : {1} ",prop.Prop, prop.Value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment