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






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

public class MainClass{
   public static void Main(){
            var q = from m in typeof(int).GetMethods()
                    group m by m.Name into gb
                    select gb;
            Dictionary<string, int> d = q.ToDictionary(k => k.Key, k => k.Count());
   }
}








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