I have an array of ints and a list of objects which contain int IDs.
If the array of ints contains 1,2, 3 etc, I just want to get the objects which contain those IDs (So those with 1, 2, 3, etc).
How could this be done in .NET 3.5?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
DaveShaw’s answer is fine if you are dealing with small sequences. If your array of IDs grows larger, a more performant approach would be to load the array into a
HashSet<T>and then perform the exact same query, except using the set instead.For this and other more complicated scenarios, you should also know about
Enumerable.Jointhat matches two sequences based upon keys and yields the desired results.