当前位置: 代码迷 >> .NET面试 >> linq to sql分组查询,该怎么处理
  详细解决方案

linq to sql分组查询,该怎么处理

热度:33   发布时间:2016-05-02 01:43:54.0
linq to sql分组查询
linq to sql分组查询
------解决方案--------------------
 string[] words = { "blueberry", "chimpanzee", "abacus", "banana", "apple", "cheese" }; 
      
        var wordGroups = 
            from w in words 
            group w by w[0] into g 
            select new { FirstLetter = g.Key, Words = g }; 
      
        foreach (var g in wordGroups) 
        { 
            Console.WriteLine("Words that start with the letter '{0}':", g.FirstLetter); 
            foreach (var w in g.Words) 
            { 
                Console.WriteLine(w); 
            } 
        } 


http://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b
  相关解决方案