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

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Reply