linq中的group by

现有如下需求,要求统计int数组中每个整数的个数:

int[] arrInt = {1,2,3,4,5,6,1,2,3,4,1,2,3 };
            var linq = from item in arrInt
                       group item by item into g//注意这里的into g,这里必须为g 表示范围变量IGrouping<int,int> 
                       select new {key=g.Key,value=g.Count() };//这里选择了整数的值为key,个数为值的匿名对象

 

posted @ 2013-06-16 20:58  程序有Bug  阅读(356)  评论(0编辑  收藏  举报