-1

Input (pseudocode):

var array1=[1,2,3,4];
var array2=[5,6,7,8];

Result (pseudocode):

var output={[1,5],[2,6],[3,7],[4,8]};
ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
  • 1
    Does this answer your question? [How do I create a single list of object pairs from two lists in C#?](https://stackoverflow.com/questions/7110762/how-do-i-create-a-single-list-of-object-pairs-from-two-lists-in-c) – Sinatr Jun 04 '20 at 07:16

2 Answers2

1

You can use LINQ's Zip method:

var output = array1.Zip(array2, (a, b) => new [] { a, b });

If you need it as a List<int> or int[], you can materialise it with .ToList() or .ToArray() respectively.

Try it online

ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
0

One more approach is to use linq Select EX:

int [] array1 =new [] { 1, 2, 3, 4 };
int [] array2 = new[] { 5, 6, 7, 8 };
var array3 = array1.Select((x, index) => new int[] { x, array2[index] }).ToArray();
MBB
  • 1,635
  • 3
  • 9
  • 19