标签:style groupby plist 计算 new 个学生 定义 return last
首先定义一个学生成绩类
public class StudentResult { public int Id { get; set; } public string No { get; set; } public string Name { get; set; } public int Num { get; set; } }
1、分页
public ClassA() { int pageIndex = 1;int pageSize = 100; var tempList = new List<StudentResult>(); var lastList = tempList.Skip((pageIndex-1)*pageIndex).Take(pageIndex).ToList(); }
2、聚合计算
public List<StudentResult> GetGroupSum(List<StudentResult> list) { var tempList = list.GroupBy(v => new { v.Id, v.No, v.Name }).Select(o => new { keys = o.Key, tempNum = o.Sum(v => v.Num) }).ToList(); var lastList = new List<StudentResult>(); tempList.ForEach(v => { lastList.Add(new StudentResult() { Id = v.keys.Id, No = v.keys.No, Name = v.keys.Name,Num = v.tempNum }); }); return lastList; }
标签:style groupby plist 计算 new 个学生 定义 return last
原文地址:https://www.cnblogs.com/liangshibo/p/12198142.html