//Linq //var result = from p in personList // group p by p.Id // into grouped // select new { Id = grouped.Key, Count = grouped.Count() } // into temp // orderby temp.Count descending // select temp; //Lambda var result = personList.GroupBy(g => g.Id…
一.先准备要使用的类: 1.Person类: class Person { public string Name { set; get; } public int Age { set; get; } public string Gender { set; get; } public override string ToString() => Name; } 2.准备要使用的List,用于分组(GroupBy): List<Person> personList = new List<…
roles.GroupBy(a => new { a.SubjectID,a.SubjectName}).Select(p => new SelectListItem() { Value = p.Key.SubjectID.ToString(), Text = p.Key.SubjectName }).ToList();…