tags:

views:

75

answers:

2

Hi, i've got a array of many strings. How can I sort the strings by alphabet?

+6  A: 

Sounds like you just want to use the Array.Sort method.

Array.Sort(myArray)

There are many overloads, some which take custom comparers (classes or delegates), but the default one should do the sorting alphabetically (ascending) as you seem to want.

Noldorin
+1 for mentioning its only the default behaviour. It won't sort reverse alphabetically, you need to trick it or implement your own sort.
Adam
Or just .Sort() if they are in a List
simendsjo
+1 Excellent answer, for more complex sorting I would take a look at the IComparable interface or Linq's Sort expression
armannvg
+1  A: 
class Program

    {
        static void Main()
        {
            string[] a = new string[]
            {
                "Egyptian",
                "Indian",
                "American",
                "Chinese",
                "Filipino",
            };
            Array.Sort(a);
            foreach (string s in a)
            {
                Console.WriteLine(s);
            }
        }
    }
Pranay Rana