score:2
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
.Union(listB)
.Union(listC)
.GroupBy(x => new { x.Index ,x.Name })
.Select(x=> new Monster(x.Key.Index,x.Key.Name,x.Sum(z=>z.Count)));
Result
index:0 name:snails count:972
index:1 name:slimes count:671
index:10 name:trolls count:152
Source: stackoverflow.com
Related Articles
- How to add Count if the duplicate index is occur when add list to another list?
- Check if a list contains all of another lists items when comparing on one property
- checking if all the items in list occur in another list using linq
- Count of duplicate items in a C# list
- Creating a list with elements count dependable from the another list
- Linq select strings from list when condition is met and save the index
- LINQ query returns old results when source list is re-initialized
- Copy a list of objects to another typed list in one line of code
- Linq get first or last element when List index out-of-range
- C#: Count occurrences of a string in a list which is in another list using LINQ?
- Find, count and index the duplicate items in array
- copy user's selected items of one list to another by index
- Linq code to get the index of an object in an array from an object within a list
- Filter one list using index value obtained from another list using linq
- C# LINQ Find List Inside Another List, Better way to code this than a foreach loop
- Selecting first or default index of list item where property in list matches a property in another list?
- Linq: Count number of times a sub list appear in another list
- Get index of first list and use it in another list
- Find duplicate objects in list when grouping on one or more fields
- Linq - OrderBy id when value in another list
- Returning 0 when count is applied in empty list using LINQ
- Get count of all items in a list that have one of the properties in another list
- LINQ: List all when count in join table equals zero
- How to get a List of Integers from a Property when another property exists within a List<int>?
- List or Array of String Contain specific word in Html Source Code
- List that groups by property and then counts distinct values of another property and writes count to list property
- Return items in one list based upon their matching index in another using Linq
- How to count write the linq query when the grouped bY column is in one table and the items are in another table
- c# How to get count of value in a List based on value in another List using LINQ
- How to get a list of duplicate objects out of another list?
- LINQ List searching multiple lists. Returning a single list
- partial view in mvc core
- "Argument data type ntext is invalid for argument 1 of len function" error
- LINQ - C# - Using lambda - Get a set of data from a Collection
- How to filter this specific list?
- Increment count in c#
- Searching any word using Linq
- Why does a Linq Cast<T> operation fail when I have an implicit cast defined?
- dedupe list object using linq
- GroupBy String and Count in LINQ
- How to convert this linq query to lambda?
- Count minus Count in GroupBy in Linq
- LinqToSql - Extension Method Resolution
- LINQ Query on Datatable to check if record exists
- Linq - How to query specific columns and return a lists
- Dynamically chose a field in a table to update
- C# Linq add elements from one list<custom> to another comparing them and changing values
- Getting Entity Framework to eager load on Group By
- How to insert new values in single column in sql databse
- How to get the properties with name, old value and new value after comparing two class objects