System Namespace Array Class
Reverses the sequence of the elements in the entire one-dimensional Array.
[ VB ]
<Serializable>
Overloads Public
Shared Sub Reverse ( _
ByVal array As Array _
)
[ C# ]
[Serializable]
public static void Reverse (
Array array
);
[ C++ ]
[Serializable]
public: static void Reverse (
Array* array
);
[JScript ]
public Serializable
static function Reverse (
array : Array
);
- array
- The one-dimensional Array to reverse.
After a call to this method, the element at myArray[i]
, where i is any index in the array, moves to myArray[j]
, where j equals ( myArray.Length + myArray.GetLowerBound ( 0 ) ) - ( i - myArray.GetLowerBound ( 0 ) ) - 1
.
The following code example shows how to reverse the sort of the values in an Array.
[ VB ]
Imports System
Imports Microsoft.VisualBasic
Public Class SamplesArray
Public Shared Sub Main ( )
' Creates and initializes a new Array.
Dim myArray As Array = Array.CreateInstance ( GetType ( String ) , 9 )
myArray.SetValue ( "The", 0 )
myArray.SetValue ( "quick", 1 )
myArray.SetValue ( "brown", 2 )
myArray.SetValue ( "fox", 3 )
myArray.SetValue ( "jumped", 4 )
myArray.SetValue ( "over", 5 )
myArray.SetValue ( "the", 6 )
myArray.SetValue ( "lazy", 7 )
myArray.SetValue ( "dog", 8 )
' Displays the values of the Array.
Response.WriteLine ( "The Array initially contains the " _
+ "following values:" )
PrintIndexAndValues ( myArray )
' Reverses the sort of the values of the Array.
Array.Reverse ( myArray )
' Displays the values of the Array.
Response.WriteLine ( "After reversing:" )
PrintIndexAndValues ( myArray )
End Sub 'Main
Public Shared Sub PrintIndexAndValues ( myArray As Array )
Dim i As Integer
For i = myArray.GetLowerBound ( 0 ) To myArray.GetUpperBound ( 0 )
Response.WriteLine ( ControlChars.Tab + "[{0}]:" + ControlChars.Tab _
+ "{1}", i, myArray.GetValue ( i ) )
Next i
End Sub
End Class
' This code produces the following output.
'
' The Array initially contains the following values:
' [0]: The
' [1]: quick
' [2]: brown
' [3]: fox
' [4]: jumped
' [5]: over
' [6]: the
' [7]: lazy
' [8]: dog
' After reversing:
' [0]: dog
' [1]: lazy
' [2]: the
' [3]: over
' [4]: jumped
' [5]: fox
' [6]: brown
' [7]: quick
' [8]: The
[ C# ]
using System;
public class SamplesArray {
public static void Main ( ) {
// Creates and initializes a new Array.
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 ( "jumped", 4 );
myArray.SetValue ( "over", 5 );
myArray.SetValue ( "the", 6 );
myArray.SetValue ( "lazy", 7 );
myArray.SetValue ( "dog", 8 );
// Displays the values of the Array.
Response.WriteLine ( "The Array initially contains the following values:" );
PrintIndexAndValues ( myArray );
// Reverses the sort of the values of the Array.
Array.Reverse ( myArray );
// Displays the values of the Array.
Response.WriteLine ( "After reversing:" );
PrintIndexAndValues ( myArray );
}
public static void PrintIndexAndValues ( Array myArray ) {
for ( int i = myArray.GetLowerBound ( 0 ); i <= myArray.GetUpperBound ( 0 ); i++ )
Response.WriteLine ( "\t[{0}]:\t{1}", i, myArray.GetValue ( i ) );
}
}
/*
This code produces the following output.
The Array initially contains the following values:
[0]: The
[1]: quick
[2]: brown
[3]: fox
[4]: jumped
[5]: over
[6]: the
[7]: lazy
[8]: dog
After reversing:
[0]: dog
[1]: lazy
[2]: the
[3]: over
[4]: jumped
[5]: fox
[6]: brown
[7]: quick
[8]: The
*/
[JScript ]
import System;
// Creates and initializes a new Array.
var myArray : System.Array= System.Array.CreateInstance ( System.String, 9 );
myArray.SetValue ( "The", 0 );
myArray.SetValue ( "quick", 1 );
myArray.SetValue ( "brown", 2 );
myArray.SetValue ( "fox", 3 );
myArray.SetValue ( "jumped", 4 );
myArray.SetValue ( "over", 5 );
myArray.SetValue ( "the", 6 );
myArray.SetValue ( "lazy", 7 );
myArray.SetValue ( "dog", 8 );
// Displays the values of the Array.
Response.WriteLine ( "The Array initially contains the following values:" );
PrintIndexAndValues ( myArray );
// Reverses the sort of the values of the Array.
System.Array.Reverse ( myArray );
// Displays the values of the Array.
Response.WriteLine ( "After reversing:" );
PrintIndexAndValues ( myArray );
function PrintIndexAndValues ( myArray : System.Array ) {
for ( var i : int = myArray.GetLowerBound ( 0 ); i <= myArray.GetUpperBound ( 0 ); i++ )
Response.WriteLine ( "\t[{0}]:\t{1}", i, myArray.GetValue ( i ) );
}
/*
This code produces the following output.
The Array initially contains the following values:
[0]: The
[1]: quick
[2]: brown
[3]: fox
[4]: jumped
[5]: over
[6]: the
[7]: lazy
[8]: dog
After reversing:
[0]: dog
[1]: lazy
[2]: the
[3]: over
[4]: jumped
[5]: fox
[6]: brown
[7]: quick
[8]: The
*/
Array Members Array.Reverse Overload List