Created
October 30, 2011 09:32
-
-
Save keithbloom/1325736 to your computer and use it in GitHub Desktop.
AddTheSequenceNumberToALinqQuery
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[] | |
{ | |
"Line A", | |
"Line B", | |
"Line C" | |
}; | |
var dict = new Dictionary<string, string>(); | |
for(int i=0; i <= lines.GetUpperBound(0); i++) | |
{ | |
dict.Add(string.Format("Address {0}", i), lines[i]); | |
} | |
foreach (var dictionary in dict) | |
{ | |
Console.WriteLine("{0} : {1} ",dictionary.Key, dictionary.Value); | |
} |
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
Key: Address 0 - Value: Line A | |
Key: Address 1 - Value: Line B | |
Key: Address 2 - Value: Line C |
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[] | |
{ | |
"Line A", | |
"Line B", | |
"Line C" | |
}; | |
var query = lines.Select(line => new | |
{ | |
Prop = string.Format("Address {0}", line.Count()), | |
Value = line | |
}); | |
foreach (var prop in query) | |
{ | |
Console.WriteLine("Prop: {0} - Value: {1} ",prop.Prop, prop.Value); | |
} |
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
Prop: Address 6 - Value: Line A | |
Prop: Address 6 - Value: Line B | |
Prop: Address 6 - Value: Line C |
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[] | |
{ | |
"Line A", | |
"Line B", | |
"Line C" | |
}; | |
var query = lines.Select((line, index) =>; new | |
{ | |
Prop = string.Format("Address {0}", index), | |
Value = line | |
}); | |
foreach (var prop in query) | |
{ | |
Console.WriteLine("Prop: {0} - Value: {1} ",prop.Prop, prop.Value); | |
} |
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
Prop: Address 0 - Value: Line A | |
Prop: Address 1 - Value: Line B | |
Prop: Address 2 - Value: Line C |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment