I have two List<T> of objects with different types (i.e., List<Apple> and List<Tiger>). Now I want to combine properties from the 2 objects to generate a new (anonymous) type of objects.
How do I achieve with LINQ?
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.
So do you just want to combine the first element of the apple list with the first element of the tiger list?
If so, and if you’re using .NET 4, you can use
Zip:If you’re not using .NET 4, you could use our implementation of
Zipin MoreLINQ.If you wanted to match apples with tigers in some other way, you probably want to use a join: