How to sort a C# List Items

The Sort method sorts all the items of a List. The following code snippet creates and sorts a List. 

List<string> AuthorList = new List<string>();
AuthorList.Add("Mahesh Chand");
AuthorList.Add("Praveen Kumar");
AuthorList.Add("Raj Kumar");
AuthorList.Add("Nipun Tomar");
AuthorList.Add("Dinesh Beniwal");
// Read all data
Console.WriteLine("Original Authors List");
foreach (var author in AuthorList)
{
    Console.WriteLine(author);
}

AuthorList.Sort();
Console.WriteLine("Sorted Authors List");
foreach (var author in AuthorList)
{
    Console.WriteLine(author);
}


Download Free book: Programming List with C#

Up Next
    Ebook Download
    View all
    Learn
    View all