1.

Order array elements in C#

Answer»

The ARRAY elements in C# can be ordered using the Array.Sort() method. This method ORDERS the array elements and can modify the array in its place. Also, different types of array elements can be handled by Array.Sort() like integers, strings etc.

A program that demonstrates the ordering of array elements using Array.Sort() method is given as follows:

using System; NAMESPACE Demo {   public class Program   {      public static void Main(string[] args)      {        int[] arr = { 23, 67, 71, 9, 57, 35, 99, 85, 25, 1 };        Console.Write("The original array is: ");        foreach (int i in arr)        {            Console.Write(i + " " );        }        Array.Sort(arr);        Console.Write("\nThe sorted array is: ");        foreach (int i in arr)        {            Console.Write(i + " " );        }      }   } }

The output of the above program is given as follows:

The original array is: 23 67 71 9 57 35 99 85 25 1 The sorted array is: 1 9 23 25 35 57 67 71 85 99


Discussion

No Comment Found