Accepted answer

If I understand correctly you can try to use linq Union combine those collections then use GroupBy and Sum get your expect result.

List<Monster> listA = new List<Monster>();

listA.Add(new Monster(0, "snails", 600));
listA.Add(new Monster(1, "slimes", 300));

List<Monster> listB = new List<Monster>();
listB.Add(new Monster(0, "snails", 72));

List<Monster> listC = new List<Monster>();
listC.Add(new Monster(0, "snails", 300));
listC.Add(new Monster(1, "slimes", 371));
listC.Add(new Monster(10, "trolls", 152));

var reuslt =  listA
        .GroupBy(x => new { x.Index ,x.Name })
        .Select(x=> new Monster(x.Key.Index,x.Key.Name,x.Sum(z=>z.Count)));

c# online


index:0  name:snails  count:972
index:1  name:slimes  count:671
index:10 name:trolls  count:152

Related Articles