Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Reverse an Array Using Chash



Firstly, set the original array −

int[] arr = { 1, 2,3 };

// Original Array
Console.WriteLine("Original Array= ");
fo            reach (int i in arr) {
   Console.WriteLine(i);
}

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

Array.Reverse(arr);

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

Example

using System;

class Demo {

   static void Main() {
      int[] arr = { 9, 32, 87, 45, 77, 56 };

      // 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();
   }
}
Updated on: 2020-06-21T15:23:20+05:30

546 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements