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]};
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]};
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.
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();