score:1
Accepted answer
If ID
is unique within list_2
you can have a faster implementation (for large lists) by converting list to dictionary
// A little bit of Linq: ToDictionary
var dict = list_2.ToDictionary(item => item.ID, item => item);
...
foreach (item in list_1) {
foo master;
if (dict.TryGetValue(item.ID, out master)) {
item.name = master.name;
item.color = master.color;
}
}
Source: stackoverflow.com
Related Query
- C# compare two Lists by one Property and change value of first List
- How to compare two lists and change one property
- How to compare two lists and set value to list property
- How do I compare two lists where one list starts with the other, and only return the "overhang" elements?
- Compare two lists - If any objects property in one list have changed or a new object in list been added, return that object
- Compare two lists and update only if the first list if condition match on second list
- Compare Two Lists Via One Property Using LINQ
- Left join on two Lists and maintain one property from the right with Linq
- Merge two Lists in C# and merge objects with the same id into one list item
- Intersect two lists and return the similarity with the preserved order of the original first string value
- Compare id's of objects in two lists and get the list of objects that includes objects with ids occurring in both of them
- Compare two lists and save matching column to a separate list
- Compare two list if match found update first list property
- How can I compare two Lists and create another list where the match?
- find list elements which are similar to other list elements by 3 properties and then add value from the second one to the first
- How to use linq to assign two lists and an int to create one list of a new object?
- LINQ Compare two lists where property value is not equal
- Linq extension. Change property value in source list
- Compare values between 3 lists and add missing values from first list into the remaining 2 lists - C#
- How to compare two list and get the differences from first list?
- C# LINQ code for two list compare and replace
- Compare two lists and add the difference to third list
- Compare two list of objects and select common and difference records based some property
- Find a string in the list and change value of another property using linq (complicated)
- Using LINQ. How can I compare two simple lists to give another list of objects in the new and not in the old list?
- Compare 2 List of object's boolean property and return the boolean value true if they matches
- Find and change the value of first element in list that meets a requirement, do something else if not found
- How to avoid two foreach loops and assign conditionally property value from one to another?
- How to compare two list values and round them to first list values without adding them internally
- how to compare two list and subtract single column value in c#
More Query from same tag
- MVC 5 ASP.NET IEnumerable<Item> does not contain a definition for "Inspection" and no extension method "inspection" accepting a first argument of type
- order by in lambda expressions
- How to Build LINQ for this SQL Statement?
- SelectMany cannot be inferred from the usage
- C# LINQ, script with JOIN and GroupBy throwing exception
- Get same keys from two different dictionaries
- LINQ - Contains in?
- Decimal.ToString not working if the value is zero
- C# - group list by TimeSpan starting from specific start point
- LINQ to Entities does not recognize the method '<>f__AnonymousType4`1[System.String] get_Item(Int32)'
- Why is Enumerable Min or Max inconsistent between collections of reference and value types?
- Linq select from CRM public view
- Is LINQ breadth-first or depth-first?
- Whats the 'modern' way to find common items in two Lists<T> of objects?
- How to get DropDownList text from selected value via Linq
- how to check that a list contains another list C#
- Find duplicate row in a datatable by id - add the duplicate column values as concatented string to a new column then remove dulplicate column
- Difference Between Select and SelectMany
- Sum in Linq to Object query vb.net
- Most Efficient way to filter a List that contains (almost) Duplicates in .Net
- InnerJoin vs Contains, which is faster
- Count() returns incorrect result on IEnumerable<T> filled using LINQ
- how to display the data in grid view using linq query in web form
- LINQ to Entities similar code
- How do I build Expression Call for Any Method with generic parameter
- How to Sort a List of Objects by dictionary value?
- Array operations with n-dimensional array using LINQ (C#)
- LINQ - Inserting new record - error about adding an entity that is not new
- How can I convert a DataTable to an IEnumerable<Dictionary<string, object>>?
- Improve performance on LINQ Query