Convert query to Dictionary : ToDictionary « LINQ « C# / C Sharp






Convert query to Dictionary

 
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());
   }
}

 








Related examples in the same category

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