Solved

What's the LINQ to ensure two lists match?

Posted on 2012-03-13
4
438 Views
Last Modified: 2012-03-13
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.
0
Comment
Question by:newbieweb
  • 2
4 Comments
 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 500 total points
ID: 37716209
Use the contains function of the list.  Something like:
myObjectsList.Where (mol ->  myListOfIds.Contains(mol.Id) )
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 37716282
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?
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 37716292
Never mind. I didn't read the question properly  : \

I think ged325 has you sorted out  = )
0
 

Author Closing Comment

by:newbieweb
ID: 37717782
Thanks!
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question