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 Query
- How to add Count if the duplicate index is occur when add list to another list?
- How can I add have a property of a list populated with a unique number when I populate the list?
- How to count write the linq query when the grouped bY column is in one table and the items are in another table
- How to make the Linq Query as efficient when select list inside the another select list
- How do I get the objects from a list of objects which contain a duplicate property inside of another list in the object?
- How can I get the index of an item in a list in a single step?
- How to count the number of code lines in a C# solution, without comments and empty lines, and other redundant stuff, etc?
- Why does adding a list to another list, using add range, remove the elements from the first list?
- how add the list of strings into string using linq?
- How to get the list index of the nearest number?
- How to find the index of next matching element in list using LINQ
- How do I use Linq to find the elements of a list that are not present in another list?
- checking if all the items in list occur in another list using linq
- Linq - How can a add the contents of two list
- How to order a List by the order of another 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
- How to group by multiple fields and get the count of another field
- how split the List of strings into another Lists if particular string matches condition using linq?
- Best way to join 3 lists and count how many times an ID is in the list using linq
- How can I compare two Lists and create another list where the match?
- How to group by list of values and then count the amount of entries per value
- How to get the list elements that are not into another list C#
- How to find the key of a dictionary when the value is a list of objects in C#?
- How to get the index of int array when using linq query
- How to count the occurence of each number in list A that is exist in list B and return zero if not existed?
- Find, count and index the duplicate items in array
- How to replace large count of string values from list found in the string
- How can I check the number of calls to the database in LINQ query when using .NET Core and Code First?
- How can I add an index to a LINQ query when there is a grouping?
More Query from same tag
- Why is this LINQ query not working correctly?
- Updating a record using LINQ Context?
- Issues with LINQ statement with defining an element of a collection
- Linq Distinct not bringing back the correct results
- What is the equivalent LINQ to SQL query expression of this SQL statement?
- Is there a concise built-in way to get a list item by index that is not going to throw an exception?
- How can I use a List<> as the condition for my where clause with Linq?
- How can I use Linq to build a c# object from xml where an element has zero or more elements of the same type?
- C# linq anonymous include
- Using EntityFunctions without entity framework
- LINQ Query IList<string> to JSon Format
- LINQ query working fine in Dot Net Core 2.2 but in 3.1
- Can this be done only with c# linq
- Convert string time to datetime or timespan in entity framework query
- LINQ - how to get n records from two tables?
- how to build html navigation bar dynamically using data from database
- data grid does not show data in C# wpf application
- SQL LIKE in Linq
- Function which will return particular node from tree structure
- How to execute Datatable Linq Union
- entity framework linq query, get top N postIDs from favorite's table based on count
- Return different objects with one LINQtoSQL statement
- Is there generic way of checking if record is duplicated? It needs to be checked by Unique Constraint in the database
- Could not find an implementation of the query pattern for source type 'System.Data.Entity.DbSet` 'Where' not found
- Linq to Entities or SQL Query Diet
- Int overload for IEnumerable.Select not working (used for row count)
- How can I write Take(1) in query syntax
- Not understanding LINQ query
- Get the next object in list after the object with current ID
- Need to filter a datatable on 2 columns which creates a unique combination?