How to print one dimensional array in reverse order?


Firstly, declare and initialize one dimensional array.

int[] arr = { 35, 12, 66, 90, 34, 2, 64 };

Now, use the following to reverse −

Array.Reverse(arr);

The following is the complete code to reverse a one-dimensional array;

Example

 Live Demo

using System;
class Demo {
   static void Main() {

      int[] arr = { 76, 12, 66, 90, 34, 2, 64 };
      // Initial 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=
76
12
66
90
34
2
64
Reversed Array=
64
2
34
90
66
12
76

Updated on: 22-Jun-2020

328 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements