Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combine each element from Array 1 with each element from Array 2

Tags:

c#

I'll keep this simple. My dataset is as follows:

Array 1:

James
Bob
Jim

Array 2:

0
1
2

I want to create a new array by joining the two arrays so they produce something like the following:

James 0
James 1
James 2
Bob 0
Bob 1
Bob 2
Jim 0
Jim 1
Jim 2

How can it be done in C#. I've came into this problem before, I remember using extension methods but I have no idea what area of Set Theory this falls under.

like image 974
James Jeffery Avatar asked Feb 15 '26 08:02

James Jeffery


1 Answers

You're looking for a cross product:

from a in a1
from b in a2
select new { a, b }
like image 184
usr Avatar answered Feb 16 '26 20:02

usr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!