How to reverse an array in C#
To reverse an Array in C# you can use directly theArray.Reverse()
method and pass the array as parameter.Example of reversing an array in C#
using System;
using System.Linq;
public class Program
{
public static void Main(){
int[] array = { 1, 2, 3, 4 };
Array.Reverse(array);
/* Below line is used to print to console for testing purpose */
Console.WriteLine(string.Join(", ", array.ToArray()));
}
}
Output
4, 3, 2, 1