问题描述
我有一个列表包含
list< cls> Objlist =新列表< cls>();
Obj1.Name =earth;
obj1.code =1
Obj1.Value = 10;
objlist.add(Obj1);
Obj2.Name =sun ;
obj1.code =2
Obj2.value = 15;
objlist.add(Obj2);
Obj3.Name =earth;
obj1.code =1
Obj3.Value = 25;
objlist.add(Obj3);
Obj4.Name =earth;
obj1.code = 1
Obj4.Value = 35;
objlist.add(Obj4);
Obj5。名字=太阳;
obj1.code =2
Obj5.value = 50;
objlist.add(Obj5);
现在我想找到一个包含linq的子列表,即sum字段包含id的值组合总和。
Obj1。姓名=地球;
obj1.code =1
Obj1.sum = 70;
和
Obj5.Name =sun;
obj1.code =2
Obj5.sum = 65;
tks in advanc e
I have a list containg
list<cls> Objlist = new list<cls>();
Obj1.Name="earth";
obj1.code="1"
Obj1.Value = 10;
objlist.add(Obj1);
Obj2.Name="sun";
obj1.code="2"
Obj2.value = 15;
objlist.add(Obj2);
Obj3.Name = "earth";
obj1.code="1"
Obj3.Value = 25;
objlist.add(Obj3);
Obj4.Name = "earth";
obj1.code="1"
Obj4.Value = 35;
objlist.add(Obj4);
Obj5.Name="sun";
obj1.code="2"
Obj5.value = 50;
objlist.add(Obj5);
Now i want to find a sub list using linq which contain,ie sum field contain sum of value group by id.
Obj1.Name="earth";
obj1.code="1"
Obj1.sum= 70;
and
Obj5.Name="sun";
obj1.code="2"
Obj5.sum= 65;
tks in advance
推荐答案
这篇关于使用Linq在List上的Aggregete函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!