How to reverse a C# List

The Reverse method reverses the items of a List. The following code snippet creates and reverses 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.Reverse();
Console.WriteLine("Reversed 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