←
ToArrayToDictionaryLINQ
Creates a Dictionary from an IEnumerable.
Syntax
source.ToDictionary(keySelector, elementSelector?)Example
Enter values below to update the example in real time.
var→people→new→Id→Name→dict→ToDictionary→Console→WriteLine→Alice→var people = new[] {
new { Id = 1, Name = "Alice" },
new { Id = 2, Name = "Bob" }
};
var dict = people.ToDictionary(p => p.Id, p => p.Name);
Console.WriteLine(dict[1]); // Alice