We help IT Professionals succeed at work.

What's the LINQ to ensure two lists match?

have a list of string value, which ar Id's

List<string> myListOfIds

I also have an object with an Id, is a list

List<MyObject> myObjectsList

I need to extract a list of all MyObject objects with Id's found in myListOfIds

Thanks.
Comment
Watch Question

Senior .Net Developer
CERTIFIED EXPERT
Commented:
Use the contains function of the list.  Something like:
myObjectsList.Where (mol ->  myListOfIds.Contains(mol.Id) )
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2015

Commented:
Depends on what you mean by "match". Two lists will only match, by default, if their corresponding references match. If you need to check on a particular property, then you might need to involve some lamdas at some point.

Can you clarify your matching criteria?
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2015

Commented:
Never mind. I didn't read the question properly  : \

I think ged325 has you sorted out  = )
curiouswebsterSoftware Engineer

Author

Commented:
Thanks!

Explore More ContentExplore courses, solutions, and other research materials related to this topic.