1 //分组 2 var ll= lst.GroupBy(x => new { x.Id, x.Name }).Select(x => new 3 { 4 Key = x.Key, 5 Id = x.First().Id, 6 Name = x.First().Name, 7 Count = x.Sum(s => s.Value) 8 }); 9 10 11 //排序 12 List<int> list = new List<int>(); 13 list.Sort();// 升序排序 14 list.Reverse();// 反转顺序 15 16 List<int> list= new List<int>(){5,1,22,11,4}; 17 list.Sort((x, y) => x.CompareTo(y));//升序 18 list.Sort((x, y) => -x.CompareTo(y));//降序 19 20 //定义一个集合 21 var list = new List<Object>();//这里的Type为对象类型 22 //假设list已经有数据存进去,根据对象的某个字段升序或降序 23 var orderInfo = list.OrderByDescending(a => a.ProductID).ToList();//降序 24 var orderInfo = list.OrderBy(a => a.ProductID).ToList();//升序