写个 LINQ的分组
// 实现多key分组的扩展函数版本 var sums = empList .GroupBy(x => new { x.Age, x.Sex }) .Select(group => new { Peo = group.Key, Count = group.Count() }); foreach (var employee in sums) { Console.WriteLine(employee.Count + ": " + employee.Peo); } // 实现多key分组的lambda版本 var sums2 = from emp in empList group emp by new { emp.Age, emp.Sex } into g select new { Peo = g.Key, Count = g.Count() }; foreach (var employee in sums) { Console.WriteLine(employee.Count + ": " + employee.Peo); }