Use the Sort() method to sort the elements in a char array : Array object : Data Structure C# Examples


C# Examples » Data Structure » Array object »

 

Use the Sort() method to sort the elements in a char array









    
using  System;

class  MainClass
{

    public  static  void  Main()
    {
        char[]  charArray  =  {'w',  'e',  'l',  'c',  'o',  'm',  'e'};
        Array.Sort(charArray);    //  sort  the  elements
        Console.WriteLine("Sorted  charArray:");
        for  (int  i  =  0;  i  <  charArray.Length;  i++)
        {
            Console.WriteLine("charArray["  +  i  +  "]  =  "  +
                charArray[i]);
        }
    }

}
    
   
  
   



Output

Sorted charArray:
charArray[0] = c
charArray[1] = e
charArray[2] = e
charArray[3] = l
charArray[4] = m
charArray[5] = o
charArray[6] = w


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Data Structure
» Array object