C# Program to reverse array elements


In this program, You will learn how to reverse array elements in C#.


Array List is: 11 12 13 14 15

Reverse => 15 14 13 12 11

Example: How to reverse array elements in C#.

using System;
public class Program
{
	public static void Main(string[] args)
	{
		int i, j,  temp;
		int[] arr = new int[5];

		Console.Write("Enter five numbers:");

		for (i = 0; i < arr.Length; i++)
		{
			arr[i] = Convert.ToInt32(Console.ReadLine());
		}

		j = 5 - 1;
		for (i = 0; i < j; i++)
		{
			temp = arr[i];
			arr[i] = arr[j];
			arr[j] = temp;
			j--;
		}

		Console.Write("After Reverse Array Elements:");
		for (i = 0; i < 5; i++)
		{
			Console.Write(arr[i] + " ");
		}
	}
}

Output:

Enter five numbers:10
20
30
40
50
After Reverse Array Elements: 50 40 30 20 10