Reverse an Array items in c#

In this article I will explain that how to Reverse an Array items in Array.
  • 3232

Reverse the items of static method of the Array class reverses the order of items in an array. Similar to the Sort method, you can just pass an array as a parameter of the Reverse of the items.

namespace demo_arraylist

{

    class Program

    {

        static void Main(string[] args)

        {

            Array SArray = Array.CreateInstance(typeof(String), 5);

            SArray.SetValue("Ajay", 0);

            SArray.SetValue("Sanjay", 1);

            SArray.SetValue("Rajiv", 2);

            SArray.SetValue("Aryan", 3);

            SArray.SetValue("Manish", 4);

            Console.WriteLine("Actual Array");

            Console.WriteLine("______________________");

            foreach (string str in SArray)

            {

                Console.WriteLine(str);

            }

            Console.WriteLine();

            Console.WriteLine("Reversed Array");

            Console.WriteLine("_______________________");

            Array.Reverse(SArray);

            foreach (string str in SArray)

            {

                Console.WriteLine(str);

            }

            Console.ReadKey();

        }

    }

}

Output

reverse_items.jpg

Ask Your Question 

Got a programming related question? You may want to post your question here 

Programming Answers here

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.