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






ToDictionary: convert query result to Dictionary

 
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"]);
    }
}

 








Related examples in the same category

1.Convert query to Dictionary
2.Calling the First ToDictionary Prototype
3.Second ToDictionary
4.ToDictionary for an object list
5.ToDictionary with IEqualityComparer