Use the Sort() method to sort the elements in a string array : String Array « String « C# / CSharp Tutorial






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]);
    }
  }

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








5.5.String Array
5.5.1.Initialize string arrays
5.5.2.Change element in a string array
5.5.3.Use the Sort() method to sort the elements in a string array
5.5.4.A two-dimensional rectangular string array