This post will discuss how to reverse a list in C#.

1. Using Enumerable.Reverse() method

To create a reversed copy of the original list, we can use the Enumerable.Reverse() method. It just creates a new sequence with elements in the reverse order without modifying the underlying list. The following code example reverses a list using the Reverse() method.

Download  Run Code

2. Using List<T>.Reverse() method

To reverse the order of the elements within the specified list, we can use the List<T>.Reverse() method. List<T>.Reverse() uses an in-place algorithm. That means that the conversion occurs without using any auxiliary list by overwriting the existing elements of the specified list.

Download  Run Code

3. Using List<T>.RemoveAt() method

Another approach to in-place reverse a list is to reorder the elements present in the list using a for-loop, which removes an element from the end of the list and insert it into the very beginning, one at a time.

Download  Run Code

4. Using Recursion

The following code example demonstrates how to use recursion to in-place reverse a list.

Download  Run Code

5. Naive Solution

We can also write our own custom routine to reverse the list in-place.

Download  Run Code

That’s all about reversing a list in C#.