我有一个这样的对象列表:
List<ClassName> list = new List<ClassName>();
list.Add(new ClassName()
{
Name = 1,
Amount = 5
});
list.Add(new ClassName()
{
Name = 2,
Amount = 10
});
list.Add(new ClassName()
{
Name = 1,
Amount = 20
});
list.Add(new ClassName()
{
Name = 3,
Amount = 10
});
list.Add(new ClassName()
{
Name = 3,
Amount = 15
});
现在我想通过属性来总结这个列表Name
。结果应该包含每个条目和具有相同条目Name
的总和。所以这将是预期的结果:Amount
Name
List<ClassName> list = new List<ClassName>();
list.Add(new ClassName()
{
Name = 1,
Amount = 25
});
list.Add(new ClassName()
{
Name = 2,
Amount = 10
});
list.Add(new ClassName()
{
Name = 3,
Amount = 25
});
我该如何存档?