Friday, October 6, 2017

Linq query between two lists | Update one list with another list based on a condition

Let's say we have 2 lists ListOne and ListTwo and we want to update the ListOne.Name with ListTwo.Name whenever there is a match with the ID in the both lists using linq then below is the simplest query
ListOne.Join(ListTwo, (list1) => list1.Id, (list2) => list2.Id, (list1, list2) =>
{
list1.Name = list2.Name;
return list1;
}).ToList();
view raw gistfile1.txt hosted with ❤ by GitHub