C# Program to Reverse an Array



Firstly, set the original array −

int[] arr = { 15, 16, 17, 18 };
// Original Array
Console.WriteLine("Original Array= ");
foreach (int i in arr) {
   Console.WriteLine(i);
}

Now, use the Array.reverse() method to reverse the array −

Array.Reverse(arr);

Example

The following is the complete code to reverse an array in C#

Live Demo

using System;
class Demo {
   static void Main() {
      int[] arr = { 15, 16, 17, 18 };
      // Original Array
      Console.WriteLine("Original Array= ");
      foreach (int i in arr) {
         Console.WriteLine(i);
      }
      // Reverse Array
      Array.Reverse(arr);
      Console.WriteLine("Reversed Array= ");
      foreach (int j in arr) {
         Console.WriteLine(j);
      }
      Console.ReadLine();
   }
}

Output

Original Array=  
15
16
17
18
Reversed Array=  
18
17
16
15
Updated on: 2020-06-19T11:30:41+05:30

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements