Just a bit rusty on the old linq.
If I have 2 collections EG NewCustomerList and OldCustomerList and see if a surname exists already how would I do it in linq .I am sure there are many ways. SelectMany rings a bell but forgot how to do it!
In a forEach I would do something like that. What is the equivalent in linq?
foreach (var oldCustomer in OldCustomerList)
{
foreach (var newCustomer in NewCustomerList.Where(x => x.Surname == oldCustomer.Surname))
{
break;
}
}
Any Suggestions? Thanks a lot
So you’re trying to see whether any of the old customer surnames are in the new customer list?
One simple option: do a join and see if it’s empty:
(I’ve used a null projection because we really don’t care about the join result.)
Another option:
I suspect you may find that you actually want the result in terms of which surnames are in common though… if you can give us more context, we may be able to help you more.