📜  linq select count group by c#代码示例

📅  最后修改于: 2022-03-11 14:49:24.090000             🧑  作者: Mango

代码示例1
foreach(var line in data.GroupBy(info => info.metric)
                        .Select(group => new { 
                             Metric = group.Key, 
                             Count = group.Count() 
                        })
                        .OrderBy(x => x.Metric))
{
     Console.WriteLine("{0} {1}", line.Metric, line.Count);
}