Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Here is an example code in C# that sorts a list of strings in alphabetical order:

using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        List<string> names = new List<string>() {"John", "Alice", "Bob", "Mary"};

        names.Sort();

        foreach (string name in names)
        {
            Console.WriteLine(name);
        }
    }
}

The List<T>.Sort method is used to sort the list of strings in-place. The foreach loop is used to print the sorted list.