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

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...