C# Reverse Array

We use the Array.Reverse() function to reverse an array, or in other words to sort the elements in reverse order.

In the example code below, first the correct order of the array and then the reverse order are printed on the screen.

namespace ConsoleApplicationTest
{
    class Program
    {
        static void Main(string[] args)
        {
            string [] array = { "Sugar", "Salt", "Cake", "Water", "Soda" };

            foreach (string value in array)
            {
                Console.WriteLine(value);
            }

            Console.WriteLine("\nWrite to Screen in Reverse\n");
            
            Array.Reverse(array);

            foreach (string value in array)
            {
                Console.WriteLine(value);
            }

            Console.WriteLine();

            Console.ReadLine();
        }
    }
}

Note : \n allows one line to go down.



You May Interest

Splitting a String By Desired Character in C#

C# Finding the Operating System Username

C# How To Find The Average Of 10 Numbers Using A While Loop

Finding the Index Order of a Character in a String in C#

C# Finding the Path to the Windows Folder