Use the Sort() method to sort the elements in a string array : String Array : String C# Examples


C# Examples » String » String Array »

 

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









    
using  System;

class  MainClass
{

    public  static  void  Main()
    {
        
        string[]  stringArray  =  {"t",  "i",  "a",  "test",  "abc123",  "abc345"};
        Array.Sort(stringArray);    
        Console.WriteLine("Sorted  stringArray:");
        for  (int  i  =  0;  i  <  stringArray.Length;  i++)
        {
            Console.WriteLine("stringArray["  +  i  +  "]  =  "  +  stringArray[i]);
        }
    }

}
    
   
  
   



Output

Sorted stringArray:
stringArray[0] = a
stringArray[1] = abc123
stringArray[2] = abc345
stringArray[3] = i
stringArray[4] = t
stringArray[5] = test


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo String
» String Array