C# Array Reverse(Array)
Description
Array Reverse(Array)
reverses the sequence of the elements
in the entire one-dimensional Array.
Syntax
Array.Reverse(Array)
has the following syntax.
public static void Reverse(
Array array
)
Parameters
Array.Reverse(Array)
has the following parameters.
array
- The one-dimensional Array to reverse.
Returns
Array.Reverse(Array)
method returns
Example
As the following example shows, the Reverse method can be used to reverse a jagged array.
// w w w.j a v a 2s .co m
using System;
using System.Globalization;
public class Example
{
public static void Main()
{
int nMonths = DateTimeFormatInfo.CurrentInfo.Calendar.GetMonthsInYear(DateTime.Now.Year);
int[][] months = new int[nMonths][];
Array.Reverse(months);
Array myArray=Array.CreateInstance( typeof(String), 9 );
myArray.SetValue( "The", 0 );
myArray.SetValue( "quick", 1 );
myArray.SetValue( "brown", 2 );
myArray.SetValue( "fox", 3 );
myArray.SetValue( "jumps", 4 );
myArray.SetValue( "over", 5 );
myArray.SetValue( "the", 6 );
myArray.SetValue( "lazy", 7 );
myArray.SetValue( "dog", 8 );
Array.Reverse( myArray );
for ( int i = myArray.GetLowerBound(0); i <= myArray.GetUpperBound(0); i++ )
Console.WriteLine( "\t[{0}]:\t{1}", i, myArray.GetValue( i ) );
}
}
The code above generates the following result.