
How can you reverse the order of the elements in your List? The Reverse method can be useful in steps of certain algorithms that require a reversed order. In this short example, we use Reverse on a List of strings in a C# program.

Here we see how you can reverse the order of the element collection in your List. You can use this method on an unsorted List, or you can combine this with an ascending sorting method to get a descending sort. This means you can change the ordering from A - Z to Z - A, which can be very useful.
This C# example program reverses the elements in a List. The Reverse method is used.
Program that uses Reverse [C#]
using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
List<string> list = new List<string>();
list.Add("anchovy");
list.Add("barracuda");
list.Add("bass");
list.Add("viperfish");
// Reverse List in-place, no new variables required
list.Reverse();
foreach (string value in list)
{
Console.WriteLine(value);
}
}
}
Output
viperfish
bass
barracuda
anchovyThe List Reverse method, which internally just uses the Array.Reverse method, provides an easy way to reverse the order of the elements in your List. It does not change any of the individual elements in any way. More information is available about the Array.Reverse method.
Array.Reverse Inverts Array Ordering Collections