How to sort an array in C#?

CsharpProgrammingServer Side Programming

The following is the integer array.

int[] arr = { 99, 43, 86 };

To sort, use the Sort() method.

Array.Sort(arr);

The following is the complete code displaying how to sort an array in C# using the Sort() method.

Example

 Live Demo

using System;
class Demo {
   static void Main() {
      int[] arr = { 99, 43, 86 };
      // sort
      Array.Sort(arr);
      Console.WriteLine("Sorted List");
      foreach (int res in arr) {
         Console.Write("\n"+res);
      }
      Console.WriteLine();
   }
}

Output

Sorted List
43
86
99
raja
Published on 18-Sep-2018 16:18:03
Advertisements