Given lists l1 = {1, 2} and l2 = {4, 5, 6 } I want to get a new list that has elements:
rez = { {1, 4}, {1, 5}, {1, 6}, {2, 4}, {2, 5}, {2, 6} }
Suggestions?
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.
Yes it is possible. Eric Lippert wrote a very good article on this topic:
Computing a Cartesian Product with LINQ
If you only have 2 lists, then you could directly use multiple
fromlike this:or even:
But the solution given by Eric Lippert in the previous article allows you to compute the cartesian product of several sequences. With the following extension method:
You could write:
And obtain: