static void Main(string[] args)
Console.Write("Input the number of elements to be stored in the first array: ");
if (int.TryParse(Console.ReadLine(), out int size) && size > 0)
int[] firstArray = new int[size];
int[] secondArray = new int[size];
int[] mergedArray = new int[size * 2];
Console.WriteLine($"Input {size} elements in the first array:");
for (int i = 0; i < size; i++)
Console.Write($"element - {i} : ");
if (int.TryParse(Console.ReadLine(), out int element))
Console.WriteLine("Invalid input. Please enter a valid integer.");
Console.Write($"Input the number of elements to be stored in the second array: ");
if (int.TryParse(Console.ReadLine(), out int secondSize) && secondSize == size)
Console.WriteLine($"Input {size} elements in the second array:");
for (int i = 0; i < size; i++)
Console.Write($"element - {i} : ");
if (int.TryParse(Console.ReadLine(), out int element))
secondArray[i] = element;
Console.WriteLine("Invalid input. Please enter a valid integer.");
for (int i = 0; i < size; i++)
mergedArray[i * 2] = firstArray[i];
mergedArray[i * 2 + 1] = secondArray[i];
Console.WriteLine("\nThe merged array in ascending order is:");
foreach (int element in mergedArray)
Console.Write(element + " ");
Console.WriteLine("Invalid input for the second array. It must have the same size as the first array.");
Console.WriteLine("Invalid input. Please enter a positive integer for the size of the first array.");