日期:2014-05-20 浏览次数:20797 次
int[] scores = { 70, 81, 62, 53, 92, 85, 77, 88, 60, 83, 100, 78, 71 }; var query = from x in scores group x by x / 10 into g select string.Format("{0}~{1}分数段的人有{2}个。"g.Key, g.Key + 10, g.Count()); foreach (string item in query) { Console.WriteLine(item); }
------解决方案--------------------
晕,修改下
int[] scores = { 70, 81, 62, 53, 92, 85, 77, 88, 60, 83, 100, 78, 71 }; var query = from x in scores group x by x / 10 into g orderby g.Key select string.Format("{0}~{1}分数段的人有{2}个。", g.Key * 10, g.Key * 10 + 9, g.Count()); foreach (string item in query) { Console.WriteLine(item); }