
There are many ways to reverse elements. One way applies the Reverse extension method for a declarative and clear syntax. Found in the System.Linq namespace, the Reverse method acts upon many collection types. It returns a collection containing the elements in the opposite order.

This example demonstrates how you can invoke the Reverse extension method from the System.Linq namespace. Notice that the program includes the System.Linq namespace at the top; this is important. The Reverse extension method is not defined on the array type; instead, it is defined in the LINQ library and can act upon arrays effectively. This program writes the opposite element order in the array to the screen.
This C# example program uses the Reverse extension method. It requires System.Linq.
Program that uses Reverse extension method [C#]
using System;
using System.Linq;
class Program
{
static void Main()
{
// Create an array.
int[] array = { 1, 2, 4 };
// Call reverse extension method on the array.
var reverse = array.Reverse();
// Write contents of array to screen.
foreach (int value in reverse)
{
Console.WriteLine(value);
}
}
}
Output
4
2
1
Performance concerns. Unfortunately, the Reverse extension method will likely have worse performance in many cases than other methods. This is because there is an iterator used in the LINQ method; this requires more allocations and in the end results in worse performance in many cases. To achieve better performance, it would be possible to use the Array.Reverse method, or even describe the imperative steps to reversing each element programmatically.
Array.ReverseTip: Typically, LINQ methods will degrade performance on low-level value type collections.

We described the Reverse extension method in the C# programming language and System.Linq namespace. While the Reverse method is effective, it may not be ideal for all programs in this context. Please carefully weigh the performance and conciseness demands of your program before choosing Reverse; the declarative, function-based syntax of Reverse is very short but not optimally fast.
LINQ Examples