Created
February 25, 2011 13:59
-
-
Save keithbloom/843816 to your computer and use it in GitHub Desktop.
LINQ Select query which includes the iterator index in the projection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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