HomeCSharpHow to Reverse an Array in C# ?

How to Reverse an Array in C# ?

If you need to reverse the values of an array , you could use the Reverse extension method.

How to Reverse an Array in C# ?

For example , assume that the array of integer contains the following values 10, 1, 3, 67 . Below is a sample code snippet that demonstrates how to reverse an array in C# using the reverse extension method.

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
namespace GinktageConsoleApp
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            int[] InputArray = new int[4] { 10, 1, 3, 67 };
            IEnumerable<int> ReversedArray = InputArray.Reverse();
            foreach(var item in ReversedArray)
                Console.WriteLine(item);
           Console.ReadLine();
        }     
    }
    
}

1

Leave a Reply

You May Also Like

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...