Array - Reverse

Reverses the sequence of the elements in the entire one-dimensional.

Try it

public static void Main()
{
	int[] sourceArray = { 2, 5, 3, 8, 6, 5, 4, 15, 19, 32 };
	
	 // Displays the values of the Array.
    Console.WriteLine( "Original values:" );
    PrintValues(sourceArray);

	// C# Extension Method: Array - Reverse
    sourceArray.Reverse();

	Console.WriteLine( "Values after calling Reverse method:" );
    PrintValues(sourceArray);
}

public static void PrintValues(Array myArr)
{
    int i = 0;
    int cols = myArr.GetLength(myArr.Rank - 1);
    foreach (object o in myArr)
    {
        if ( i < cols )
        {
            i++;
        }
        else
        {
            Console.WriteLine();
            i = 1;
        }
        Console.Write( "\t{0}", o);
    }
    Console.WriteLine();
}

View Source
using System;

public static partial class Extensions
{
    /// <summary>
    ///     Reverses the sequence of the elements in the entire one-dimensional .
    /// </summary>
    /// <param name="array">The one-dimensional  to reverse.</param>
    public static void Reverse(this Array array)
    {
        Array.Reverse(array);
    }

    /// <summary>
    ///     Reverses the sequence of the elements in a range of elements in the one-dimensional .
    /// </summary>
    /// <param name="array">The one-dimensional  to reverse.</param>
    /// <param name="index">The starting index of the section to reverse.</param>
    /// <param name="length">The number of elements in the section to reverse.</param>
    public static void Reverse(this Array array, Int32 index, Int32 length)
    {
        Array.Reverse(array, index, length);
    }
}