var test = new List<MesStock> { new MesStock {Cuid="1", Deid="1",Pno="1",Sno="1",TotalNums=1}, new MesStock {Cuid="2", Deid="1",Pno="1",Sno="1",TotalNums=1}, new MesStock {Cuid="3",Deid="2",Pno="2",Sno="2",TotalNums=2}, new MesStock {Cuid="4",Deid="2",Pno="2",Sno="2",TotalNums=2}, new MesStock {Cuid="5",Deid="3",Pno="3",Sno="3",TotalNums=3}, }; List<MesStock> res = new List<MesStock>(); test.GroupBy(x => x.Deid + x.Pno + x.Sno, (x, y) => { var total = y.Sum(a => a.TotalNums); return y.Select(t => { t.TotalNums = total; res.Add(t); return t; }).ToList(); }).ToList(); foreach (var item in res) { Console.WriteLine(item.Cuid + " | " + item.TotalNums); }
朋友问的,,,