In order to sort the elements in a string array in C Sharp/C#, we use the sort() method. Given below is a simple example using sort() method to sort the elements in a string array.

using System;

class MainClass

  public static void Main()

    string[] urStringArray = {"xylo", "apple", "zeebra", "coderz", "heaven123", "heaven777"};
    Array.Sort(urStringArray );
    Console.WriteLine("Sorted string Array:");
    for (int i = 0; i < urStringArray.Length; i++)
      Console.WriteLine("urStringArray[" + i + "] = " + urStringArray[i]);


It will print out,
Sorted string Array:
urStringArray[0] = apple
urStringArray[1] = coderz
urStringArray[2] = heaven123
urStringArray[3] = heaven777
urStringArray[4] = xylo
urStringArray[5] = zeebra



Leave a Reply

Your email address will not be published. Required fields are marked *




Theme by HermesThemes

Copyright © 2018 CoderzHeaven. All Rights Reserved

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.