Merge two arrays and return sorted array in c# [closed]

The solution can be Linq query:

  int[] first = new int[] { 3, 5, 6, 9, 12, 14, 18, 20, 25, 28 };
  int[] second = new int[] { 30, 32, 34, 36, 38, 40, 42, 44, 46, 48 };

  int[] result = first
    .Concat(second)
    .OrderBy(x => x)
    .ToArray();

To test

  // 3, 5, 6, 9, 12, 14, 18, 20, 25, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48
  Console.Write(String.Join(", ", result));

It works, but it hardly will be accepted as a homework solution. So I hope you’ll elaborate your own code using my implementation as a testing reference.

Leave a Comment