ArrayList.Reverse メソッド
ArrayList 内およびその一部の要素の順序を反転させます。
オーバーロードの一覧
ArrayList 全体の要素の順序を反転させます。
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Overridable Sub Reverse()
[JScript] public function Reverse();
指定した範囲の要素の順序を反転させます。
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Public Overridable Sub Reverse(Integer, Integer)
[JScript] public function Reverse(int, int);
使用例
ArrayList のセクション内の値の並べ替え順序を反転させる方法の例を次に示します。
Imports System
Imports System.Collections
Imports Microsoft.VisualBasic
Public Class SamplesArrayList
Public Shared Sub Main()
' Creates and initializes a new ArrayList.
Dim myAL As New ArrayList()
myAL.Add("The")
myAL.Add("QUICK")
myAL.Add("BROWN")
myAL.Add("FOX")
myAL.Add("jumps")
myAL.Add("over")
myAL.Add("the")
myAL.Add("lazy")
myAL.Add("dog")
' Displays the values of the ArrayList.
Console.WriteLine("The ArrayList initially contains the " _
+ "following values:")
PrintIndexAndValues(myAL)
' Reverses the sort order of the values of the ArrayList.
myAL.Reverse(1, 3)
' Displays the values of the ArrayList.
Console.WriteLine("After reversing:")
PrintIndexAndValues(myAL)
End Sub 'Main
Public Shared Sub PrintIndexAndValues(myList As IEnumerable)
Dim i As Integer = 0
Dim myEnumerator As System.Collections.IEnumerator = _
myList.GetEnumerator()
While myEnumerator.MoveNext()
Console.WriteLine(ControlChars.Tab + "[{0}]:" + ControlChars.Tab _
+ "{1}", i, myEnumerator.Current)
i = i + 1
End While
Console.WriteLine()
End Sub
End Class
' This code produces the following output.
'
' The ArrayList initially contains the following values:
' [0]: The
' [1]: QUICK
' [2]: BROWN
' [3]: FOX
' [4]: jumps
' [5]: over
' [6]: the
' [7]: lazy
' [8]: dog
'
' After reversing:
' [0]: The
' [1]: FOX
' [2]: BROWN
' [3]: QUICK
' [4]: jumps
' [5]: over
' [6]: the
' [7]: lazy
' [8]: dog
[C#]
using System;
using System.Collections;
public class SamplesArrayList {
public static void Main() {
// Creates and initializes a new ArrayList.
ArrayList myAL = new ArrayList();
myAL.Add( "The" );
myAL.Add( "QUICK" );
myAL.Add( "BROWN" );
myAL.Add( "FOX" );
myAL.Add( "jumps" );
myAL.Add( "over" );
myAL.Add( "the" );
myAL.Add( "lazy" );
myAL.Add( "dog" );
// Displays the values of the ArrayList.
Console.WriteLine( "The ArrayList initially contains the following values:" );
PrintIndexAndValues( myAL );
// Reverses the sort order of the values of the ArrayList.
myAL.Reverse( 1, 3 );
// Displays the values of the ArrayList.
Console.WriteLine( "After reversing:" );
PrintIndexAndValues( myAL );
}
public static void PrintIndexAndValues( IEnumerable myList ) {
int i = 0;
System.Collections.IEnumerator myEnumerator = myList.GetEnumerator();
while ( myEnumerator.MoveNext() )
Console.WriteLine( "\t[{0}]:\t{1}", i++, myEnumerator.Current );
Console.WriteLine();
}
}
/*
This code produces the following output.
The ArrayList initially contains the following values:
[0]: The
[1]: QUICK
[2]: BROWN
[3]: FOX
[4]: jumps
[5]: over
[6]: the
[7]: lazy
[8]: dog
After reversing:
[0]: The
[1]: FOX
[2]: BROWN
[3]: QUICK
[4]: jumps
[5]: over
[6]: the
[7]: lazy
[8]: dog
*/
[C++]
#using <mscorlib.dll>
using namespace System;
using namespace System::Collections;
void PrintIndexAndValues( IEnumerable* myList );
int main() {
// Creates and initializes a new ArrayList instance.
ArrayList* myAL = new ArrayList();
myAL->Add( S"The" );
myAL->Add( S"QUICK" );
myAL->Add( S"BROWN" );
myAL->Add( S"FOX" );
myAL->Add( S"jumped" );
myAL->Add( S"over" );
myAL->Add( S"the" );
myAL->Add( S"lazy" );
myAL->Add( S"dog" );
// Displays the values of the ArrayList.
Console::WriteLine( "The ArrayList instance initially contains the following values:" );
PrintIndexAndValues( myAL );
// Reverses the sort order of the values of the ArrayList.
myAL->Reverse( 1, 3 );
// Displays the values of the ArrayList.
Console::WriteLine( "After reversing:" );
PrintIndexAndValues( myAL );
}
void PrintIndexAndValues( IEnumerable* myList ) {
int i = 0;
System::Collections::IEnumerator* myEnumerator = myList->GetEnumerator();
while ( myEnumerator->MoveNext() )
Console::WriteLine( "\t[{0}]:\t{1}", __box(i++), myEnumerator->Current );
Console::WriteLine();
}
/*
This code produces the following output.
The ArrayList instance 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]: The
[1]: FOX
[2]: BROWN
[3]: QUICK
[4]: jumped
[5]: over
[6]: the
[7]: lazy
[8]: dog
*/
[JScript]
import System;
import System.Collections;
// Creates and initializes a new ArrayList.
var myAL : ArrayList = new ArrayList();
myAL.Add( "The" );
myAL.Add( "QUICK" );
myAL.Add( "BROWN" );
myAL.Add( "FOX" );
myAL.Add( "jumped" );
myAL.Add( "over" );
myAL.Add( "the" );
myAL.Add( "lazy" );
myAL.Add( "dog" );
// Displays the values of the ArrayList.
Console.WriteLine( "The ArrayList initially contains the following values:" );
PrintIndexAndValues( myAL );
// Reverses the sort order of the values of the ArrayList.
myAL.Reverse( 1, 3 );
// Displays the values of the ArrayList.
Console.WriteLine( "After reversing:" );
PrintIndexAndValues( myAL );
function PrintIndexAndValues( myList : IEnumerable ) {
var i : int = 0;
var myEnumerator : System.Collections.IEnumerator = myList.GetEnumerator();
while ( myEnumerator.MoveNext() )
Console.WriteLine( "\t[{0}]:\t{1}", i++, myEnumerator.Current );
Console.WriteLine();
}
/*
This code produces the following output.
The ArrayList 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]: The
[1]: FOX
[2]: BROWN
[3]: QUICK
[4]: jumped
[5]: over
[6]: the
[7]: lazy
[8]: dog
*/