Sort Array in C#

In this article I will explain that how to Sort Array in Array.
  • 3454

You can call the static ArraySort method and use it to sort a string array in place. The result is an alphabetical sort. Array.Sort on it to sort it in-place. Then, it loops through all the characters and displays the elements in their new, alphabetical order.

namespace demo_array

{
    class Program
    {
        static void Main(string[] args)
        {
            //Program that uses Array.Sort of Character
            string[] a = new string[]
            {
                "Manish",
                "Raju",
                "Swati",
                "Zaineb",
                "Ajay",
                "Rajiv",
            };
            Array.Sort(a);
            foreach (string   s in a)
            {
                Console.WriteLine(s);             
            }
            Console.ReadKey();
            // Another Program that uses Array.Sort of Number
            int[] b = new int[]
               {
                  2,5,4,1,8,9,7,5,6
               };
            Array.Sort(b);
           foreach (int s in b)
            {
                Console.WriteLine(s);
            }
            Console.ReadKey();
        }
    }
}

Output

sort_array.jpg

Ask Your Question 

Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.