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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ListOne.Join(ListTwo, (list1) => list1.Id, (list2) => list2.Id, (list1, list2) => | |
{ | |
list1.Name = list2.Name; | |
return list1; | |
}).ToList(); |