using System.Collections.Generic;
public static void Main()
int[] x = { 1, 3, 5, 7 };
int[] y = { 2, 3, 4, 6, 8 };
List<int> z = MergeArrays(x, y);
Console.Write("First array:");
foreach (var number in x) Console.Write($" {number}");
Console.Write("Second array:");
foreach (var number in y) Console.Write($" {number}");
Console.Write("Merged array:");
foreach (var number in z) Console.Write($" {number}");
static List<int> MergeArrays(int[] x, int[] y)
List<int> z = new List<int>();
int xIterator = 0, yIterator = 0;
while (xIterator < x.Length && yIterator < y.Length)
if (x[xIterator] < y[yIterator])
while (xIterator < x.Length)
while (yIterator < y.Length)