# ArrayList.ReverseArrayList.ReverseArrayList.ReverseArrayList.Reverse Method

## 定義

ArrayList またはその一部の要素の順序を反転させます。Reverses the order of the elements in the ArrayList or a portion of it.

## オーバーロード

 Reverse() Reverse() Reverse() Reverse() ArrayList 全体の要素の順序を反転させます。Reverses the order of the elements in the entire ArrayList. Reverse(Int32, Int32) Reverse(Int32, Int32) Reverse(Int32, Int32) Reverse(Int32, Int32) 指定した範囲の要素の順序を反転させます。Reverses the order of the elements in the specified range.

## Reverse()Reverse()Reverse()Reverse()

ArrayList 全体の要素の順序を反転させます。Reverses the order of the elements in the entire ArrayList.

``````public:
virtual void Reverse();``````
``public virtual void Reverse ();``
``````abstract member Reverse : unit -> unit
override this.Reverse : unit -> unit``````
``Public Overridable Sub Reverse ()``

#### 例外

ArrayList は読み取り専用です。The ArrayList is read-only.

### 例

``````using namespace System;
using namespace System::Collections;
void PrintValues( IEnumerable^ myList );
int main()
{

// Creates and initializes a new ArrayList.
ArrayList^ myAL = gcnew ArrayList;

// Displays the values of the ArrayList.
Console::WriteLine( "The ArrayList initially contains the following values:" );
PrintValues( myAL );

// Reverses the sort order of the values of the ArrayList.
myAL->Reverse();

// Displays the values of the ArrayList.
Console::WriteLine( "After reversing:" );
PrintValues( myAL );
}

void PrintValues( IEnumerable^ myList )
{
IEnumerator^ myEnum = myList->GetEnumerator();
while ( myEnum->MoveNext() )
{
Object^ obj = safe_cast<Object^>(myEnum->Current);
Console::WriteLine( "   {0}", obj );
}

Console::WriteLine();
}

/*
This code produces the following output.

The ArrayList initially contains the following values:
The
quick
brown
fox
jumps
over
the
lazy
dog

After reversing:
dog
lazy
the
over
jumps
fox
brown
quick
The
*/
``````
``````using System;
using System.Collections;
public class SamplesArrayList  {

public static void Main()  {

// Creates and initializes a new ArrayList.
ArrayList myAL = new ArrayList();

// Displays the values of the ArrayList.
Console.WriteLine( "The ArrayList initially contains the following values:" );
PrintValues( myAL );

// Reverses the sort order of the values of the ArrayList.
myAL.Reverse();

// Displays the values of the ArrayList.
Console.WriteLine( "After reversing:" );
PrintValues( myAL );
}

public static void PrintValues( IEnumerable myList )  {
foreach ( Object obj in myList )
Console.WriteLine( "   {0}", obj );
Console.WriteLine();
}

}

/*
This code produces the following output.

The ArrayList initially contains the following values:
The
quick
brown
fox
jumps
over
the
lazy
dog

After reversing:
dog
lazy
the
over
jumps
fox
brown
quick
The
*/
``````
``````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()

' Displays the values of the ArrayList.
Console.WriteLine("The ArrayList initially contains the " _
+ "following values:")
PrintValues(myAL)

' Reverses the sort order of the values of the ArrayList.
myAL.Reverse()

' Displays the values of the ArrayList.
Console.WriteLine("After reversing:")
PrintValues(myAL)
End Sub

Public Shared Sub PrintValues(myList As IEnumerable)
Dim obj As [Object]
For Each obj In  myList
Console.WriteLine("   {0}", obj)
Next obj
Console.WriteLine()
End Sub 'PrintValues

End Class

' This code produces the following output.
'
' The ArrayList initially contains the following values:
'    The
'    quick
'    brown
'    fox
'    jumps
'    over
'    the
'    lazy
'    dog
'
' After reversing:
'    dog
'    lazy
'    the
'    over
'    jumps
'    fox
'    brown
'    quick
'    The

``````

### 注釈

このメソッドを使用してArray.Reverse、要素の順序を逆にするようにある要素ArrayList[i] i は、範囲内の任意のインデックスに移動しますArrayList[j] j と等しい`index` + `index` + `count` -i - 1。This method uses Array.Reverse to reverse the order of the elements, such that the element at ArrayList [i], where i is any index within the range, moves to ArrayList [j], where j equals `index` + `index` + `count` - i - 1.

このメソッドは O (`n`) 操作、`n`Countします。This method is an O(`n`) operation, where `n` is Count.

## Reverse(Int32, Int32)Reverse(Int32, Int32)Reverse(Int32, Int32)Reverse(Int32, Int32)

``````public:
virtual void Reverse(int index, int count);``````
``public virtual void Reverse (int index, int count);``
``````abstract member Reverse : int * int -> unit
override this.Reverse : int * int -> unit``````
``Public Overridable Sub Reverse (index As Integer, count As Integer)``

#### パラメーター

index
Int32 Int32 Int32 Int32

count
Int32 Int32 Int32 Int32

#### 例外

`index` が 0 未満です。`index` is less than zero.

または-or- `count` が 0 未満です。`count` is less than zero.

`index` および `count`ArrayList において要素の有効な範囲を表していません。`index` and `count` do not denote a valid range of elements in the ArrayList.

ArrayList は読み取り専用です。The ArrayList is read-only.

### 例

``````using namespace System;
using namespace System::Collections;
void PrintValues( IEnumerable^ myList );
int main()
{

// Creates and initializes a new ArrayList.
ArrayList^ myAL = gcnew ArrayList;

// Displays the values of the ArrayList.
Console::WriteLine( "The ArrayList initially contains the following values:" );
PrintValues( 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:" );
PrintValues( myAL );
}

void PrintValues( IEnumerable^ myList )
{
IEnumerator^ myEnum = myList->GetEnumerator();
while ( myEnum->MoveNext() )
{
Object^ obj = safe_cast<Object^>(myEnum->Current);
Console::WriteLine( "   {0}", obj );
}

Console::WriteLine();
}

/*
This code produces the following output.

The ArrayList initially contains the following values:
The
QUICK
BROWN
FOX
jumps
over
the
lazy
dog

After reversing:
The
FOX
BROWN
QUICK
jumps
over
the
lazy
dog

*/
``````
``````using System;
using System.Collections;
public class SamplesArrayList  {

public static void Main()  {

// Creates and initializes a new ArrayList.
ArrayList myAL = new ArrayList();

// Displays the values of the ArrayList.
Console.WriteLine( "The ArrayList initially contains the following values:" );
PrintValues( 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:" );
PrintValues( myAL );
}

public static void PrintValues( IEnumerable myList )  {
foreach ( Object obj in myList )
Console.WriteLine( "   {0}", obj );
Console.WriteLine();
}

}

/*
This code produces the following output.

The ArrayList initially contains the following values:
The
QUICK
BROWN
FOX
jumps
over
the
lazy
dog

After reversing:
The
FOX
BROWN
QUICK
jumps
over
the
lazy
dog

*/
``````
``````Imports System
Imports System.Collections

Public Class SamplesArrayList

Public Shared Sub Main()

' Creates and initializes a new ArrayList.
Dim myAL As New ArrayList()

' Displays the values of the ArrayList.
Console.WriteLine("The ArrayList initially contains the following values:")
PrintValues(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:")
PrintValues(myAL)

End Sub 'Main

Public Shared Sub PrintValues(myList As IEnumerable)
Dim obj As [Object]
For Each obj In  myList
Console.WriteLine("   {0}", obj)
Next obj
Console.WriteLine()
End Sub 'PrintValues

End Class 'SamplesArrayList

' This code produces the following output.
'
' The ArrayList initially contains the following values:
'    The
'    QUICK
'    BROWN
'    FOX
'    jumps
'    over
'    the
'    lazy
'    dog
'
' After reversing:
'    The
'    FOX
'    BROWN
'    QUICK
'    jumps
'    over
'    the
'    lazy
'    dog

``````

### 注釈

このメソッドを使用してArray.Reverse、要素の順序を逆にするようにある要素ArrayList[i] i は、範囲内の任意のインデックスに移動しますArrayList[j] j と等しい`index` + `index` + `count` -i - 1。This method uses Array.Reverse to reverse the order of the elements, such that the element at ArrayList [i], where i is any index within the range, moves to ArrayList [j], where j equals `index` + `index` + `count` - i - 1.

このメソッドは O (`n`) 操作、`n``count`します。This method is an O(`n`) operation, where `n` is `count`.