ToDictionary: convert query result to Dictionary : ToDictionary « LINQ « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass {
    public static void Main() {
        var scoreRecords = new[] { new {Name = "A", Score = 50},
                                new {Name = "B" , Score = 40},
                                new {Name = "C", Score = 45}
                              };
        var scoreRecordsDict = scoreRecords.ToDictionary(sr => sr.Name);
        Console.WriteLine("Bob's score: {0}", scoreRecordsDict["Bob"]);
    }
}








22.22.ToDictionary
22.22.1.Convert query to Dictionary
22.22.2.ToDictionary: convert query result to Dictionary
22.22.3.Calling the First ToDictionary Prototype
22.22.4.Second ToDictionary
22.22.5.ToDictionary for an object list
22.22.6.ToDictionary with IEqualityComparer