日期:2014-05-20 浏览次数:20930 次
class Student { public string Name { get; set; } public int Score { get; set; } public Student(string name,int score) { this.Name = name; this.Score = score; } } class Program { static void Main(string[] args) { List<Student> list=new List<Student>(); list.Add(new Student("A",60)); list.Add(new Student("B", 70)); list.Add(new Student("C", 60)); list.Add(new Student("D", 80)); list.Add(new Student("E", 60)); var query = from s in list group s by s.Score into g orderby g.Count() descending select g.Count(); IEnumerable<int> ie = query.ToList(); }
var query = list.GroupBy(g => g.Score).OrderByDescending(g=>g.Count()).First(); Console.WriteLine(string.Format("分数:{0},次数{1}",query.Key,query.Count()); foreach (var item in query) { Console.WriteLine(string.Format("姓名{0}",item.Name)); }