• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 447
  • Last Modified:

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

  • 2
1 Solution
Kyle AbrahamsSenior .Net DeveloperCommented:
Use the contains function of the list.  Something like:
myObjectsList.Where (mol ->  myListOfIds.Contains(mol.Id) )
käµfm³d 👽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?
käµfm³d 👽Commented:
Never mind. I didn't read the question properly  : \

I think ged325 has you sorted out  = )
newbiewebSr. Software EngineerAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now