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 Articles
- C# compare two Lists by one Property and change value of first List
- Linq extension. Change property value in source list
- How to compare two lists and set value to list property
- Split a list in multiple lists per value of a certain property
- Compare two list if match found update first list property
- How to compare two lists and change one property
- LINQ Compare two lists where property value is not equal
- Compare two lists - If any objects property in one list have changed or a new object in list been added, return that object
- Compare values between 3 lists and add missing values from first list into the remaining 2 lists - C#
- Find a string in the list and change value of another property using linq (complicated)
- 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 can I find the first items in a list with a different value for a property using Linq?
- Compare two lists via two property in addition to having list of unique values from third property creating new lists
- Compare 2 lists of objects and create a new list based off item properties in the first list not being present in the second with ASP.NET
- Linq - how to replace a lists property with value from another list where both keys are equal
- How to use Linq on IList, to compare first value and second value present on the list based on some conditions.?
- Compare two lists and update only if the first list if condition match on second list
- Compare 2 lists using Intersect but in 3rd list should contain match AND property from list 2
- Compare Two Lists Via One Property Using LINQ
- Filter linq list on property value
- how to check if property value of each list member is same
- Change the property of objects in a List using LINQ
- Determining the first available value in a list of integers
- How to get/find an object by property value in a list
- LINQ "Where" condition -> change value of property
- Check if a list contains all of another lists items when comparing on one property
- Linq query to exclude from a List when a property value of List of different type are equal?
- Sort a list of lists by minimum value
- Using Linq to compare a list with a set of lists in C#
- Processing records speed
- Is linq's let keyword better than its into keyword?
- Linq GroupBy multiple columns with Projection to new object
- How to yield multiple objects with respect to a multi-valued column in Dynamic Linq
- How to define IEnumerable behavior by contract?
- Remove 3 oldest elements from a List<> in C#
- XPath / linq to xml: xmlns=""testNS"" results in no result
- How to load filtered child collection on child collections with a single database call?
- How to efficiently fetch distant relation in Entity Framework projection
- How do I convert this SQL statement to linq in C#?
- LINQ to SQL Basic column search doing OR / AND of a List<string> (VB.net)
- Split single row into multiple rows in asp.net
- Is there any way to optimize this LINQ to Entities query?
- join multiple tables using LINQ
- Dynamic LINQ expression for Select with child collection (Entity Framework)
- Need help figuring out a LINQ query w/ EF
- How to get an empty list of a collection?
- How to take X amount of questions, that sum up Y amount of difficulty
- Flatten a C# Dictionary of Lists with Linq
- Why can't I assign the return of a LINQ Find() or FirstOrDefault() result?