Este artículo se tradujo de forma manual. Mueva el puntero sobre las frases del artículo para ver el texto original.
Traducción
Original
Este tema aún no ha recibido ninguna valoración - Valorar este tema

SortedList.RemoveAt (Método)

Quita el elemento en el índice especificado de un objeto SortedList.

Espacio de nombres:  System.Collections
Ensamblado:  mscorlib (en mscorlib.dll)
public virtual void RemoveAt(
	int index
)

Parámetros

index
Tipo: System.Int32
Índice de base cero del elemento que se va a quitar.
Excepción Condición
ArgumentOutOfRangeException

El valor de index está fuera del intervalo de índices válidos para el objeto SortedList.

NotSupportedException

SortedList es de sólo lectura.

O bien

La SortedList tiene un tamaño fijo.

La secuencia de índices se basa en la secuencia de ordenación. Cuando se agrega un elemento, se inserta en SortedList en el orden correcto y la indización se ajusta en consonancia. Cuando se quita un elemento, la indización también se ajusta en consonancia. Por lo tanto, el índice de un par de clave y valor específico puede cambiar a medida que se agreguen o quiten elementos del objeto SortedList.

En colecciones de elementos contiguos, como listas, los elementos que van a continuación del elemento eliminado se desplazan hacia arriba para ocupar el espacio libre. Si la colección se encuentra indizada, los índices de los elementos que se muevan también se actualizarán. Este comportamiento no se aplica a las colecciones cuyos elementos se agrupan conceptualmente en sectores de almacenamiento, como una tabla hash.

Este método es una operación O(n), donde n es Count.

En el ejemplo de código siguiente se muestra cómo se quitan elementos de un objeto SortedList.


using System;
using System.Collections;
public class SamplesSortedList  {

   public static void Main()  {

      // Creates and initializes a new SortedList.
      SortedList mySL = new SortedList();
      mySL.Add( "3c", "dog" );
      mySL.Add( "2c", "over" );
      mySL.Add( "1c", "brown" );
      mySL.Add( "1a", "The" );
      mySL.Add( "1b", "quick" );
      mySL.Add( "3a", "the" );
      mySL.Add( "3b", "lazy" );
      mySL.Add( "2a", "fox" );
      mySL.Add( "2b", "jumped" );

      // Displays the SortedList.
      Console.WriteLine( "The SortedList initially contains the following:" );
      PrintKeysAndValues( mySL );

      // Removes the element with the key "3b".
      mySL.Remove( "3b" );

      // Displays the current state of the SortedList.
      Console.WriteLine( "After removing \"lazy\":" );
      PrintKeysAndValues( mySL );

      // Removes the element at index 5.
      mySL.RemoveAt( 5 );

      // Displays the current state of the SortedList.
      Console.WriteLine( "After removing the element at index 5:" );
      PrintKeysAndValues( mySL );
   }


   public static void PrintKeysAndValues( SortedList myList )  {
      Console.WriteLine( "\t-KEY-\t-VALUE-" );
      for ( int i = 0; i < myList.Count; i++ )  {
         Console.WriteLine( "\t{0}:\t{1}", myList.GetKey(i), myList.GetByIndex(i) );
      }
      Console.WriteLine();
   }
}
/* 
This code produces the following output.

The SortedList initially contains the following:
    -KEY-    -VALUE-
    1a:    The
    1b:    quick
    1c:    brown
    2a:    fox
    2b:    jumped
    2c:    over
    3a:    the
    3b:    lazy
    3c:    dog

After removing "lazy":
    -KEY-    -VALUE-
    1a:    The
    1b:    quick
    1c:    brown
    2a:    fox
    2b:    jumped
    2c:    over
    3a:    the
    3c:    dog

After removing the element at index 5:
    -KEY-    -VALUE-
    1a:    The
    1b:    quick
    1c:    brown
    2a:    fox
    2b:    jumped
    3a:    the
    3c:    dog
*/


.NET Framework

Compatible con: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Compatible con: 4, 3.5 SP1

Windows 7, Windows Vista SP1 o posterior, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (no se admite Server Core), Windows Server 2008 R2 (se admite Server Core con SP1 o posterior), Windows Server 2003 SP2

.NET Framework no admite todas las versiones de todas las plataformas. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.
¿Le ha resultado útil?
(Caracteres restantes: 1500)
Contenido de la comunidad Agregar