Link to home
Start Free TrialLog in
Avatar of endrec
endrec

asked on

How to use LINQ or Lambda expressions to update matching items in two generic lists?

Hello,
I wanted to find out if there is an "efficient" way to find all matching items in one generic list them update items in another generic list using a filter criteria.

Example:  There is a list of customers and some customers having a missing first name and last name.  In another list there is a listing of customer details that will sometimes contain the first name and last name for some of the customers with missing info from the first list.  

How could I loop through or find only the items in list 1 where the customer first name and customer last name is null and update the first name and last name values with customer first name and customer last name values from list 2 if the commonality between the lists is not Id but address, city, and state?  Is there a way that is most efficient to do this that is not a series of nested loops?

var filteredCustomerList1 = customerlist1.FindAll(c => c.FirstName == null && c.LastName == null)...
SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
P.S.

The query finds the elements that have a matching address, but where FirstName and LastName are null. The foreach does the actual updating, in conjunction with a lambda to grab the matching record from list2.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial