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


x

Interesting BlogPosts to read

How to get an Enumerator from range of elements from ArrayList in C# ?
The code snippet shown in this blog post demonstrates how you can get the enumeraor from a range of ...
How to check for the column name in an SqlDataReader Object in C# ?
When working in ADO.NET for data access , there are times when you want to check to see if a column ...
How to convert Array to List in C#?
Want to convert array of strings to List of strings in C# ? . Below is a sample code to illustrate t...