# ArrayList.Reverse Método

## Definición

Invierte el orden de los elementos en la ArrayList o en una parte de ella.Reverses the order of the elements in the ArrayList or a portion of it.

## Sobrecargas

 Reverse() Invierte el orden de los elementos en la ArrayList completa.Reverses the order of the elements in the entire ArrayList. Reverse(Int32, Int32) Invierte el orden de los elementos en el intervalo especificado.Reverses the order of the elements in the specified range.

## Reverse()

Invierte el orden de los elementos en la ArrayList completa.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 ()``

#### Excepciones

ArrayList es de solo lectura.The ArrayList is read-only.

### Ejemplos

En el ejemplo de código siguiente se muestra cómo invertir el criterio de ordenación de los valores de ArrayList .The following code example shows how to reverse the sort order of the values in an ArrayList.

``````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.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()

' 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

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

``````

### Comentarios

Este método usa Array.Reverse para invertir el orden de los elementos, de modo que el elemento en ArrayList [i], donde i es cualquier índice dentro del intervalo, se mueve a ArrayList [j], donde j es igual `index` + `index` + `count` a-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.

Este método es una `O(n)` operación, donde `n` es Count .This method is an `O(n)` operation, where `n` is Count.

## Reverse(Int32, Int32)

Invierte el orden de los elementos en el intervalo especificado.Reverses the order of the elements in the specified range.

``````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)``

#### Parámetros

index
Int32

Índice inicial de base cero del intervalo que se va a invertir.The zero-based starting index of the range to reverse.

count
Int32

Número de elementos del intervalo que se va a invertir.The number of elements in the range to reverse.

#### Excepciones

`index` es menor que cero.`index` is less than zero.

o bien-or- `count` es menor que cero.`count` is less than zero.

`index` y `count` no denotan un intervalo válido de elementos en la ArrayList.`index` and `count` do not denote a valid range of elements in the ArrayList.

ArrayList es de solo lectura.The ArrayList is read-only.

### Ejemplos

En el ejemplo de código siguiente se muestra cómo invertir el criterio de ordenación de los valores en un intervalo de elementos de ArrayList .The following code example shows how to reverse the sort order of the values in a range of elements in an ArrayList.

``````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.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

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

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:
'    The
'    FOX
'    BROWN
'    QUICK
'    jumps
'    over
'    the
'    lazy
'    dog

``````

### Comentarios

Este método usa Array.Reverse para invertir el orden de los elementos, de modo que el elemento en ArrayList [i], donde i es cualquier índice dentro del intervalo, se mueve a ArrayList [j], donde j es igual `index` + `index` + `count` a-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.

Este método es una `O(n)` operación, donde `n` es `count` .This method is an `O(n)` operation, where `n` is `count`.