Biblioteca de clases de .NET Framework
IDictionary.Remove (Método)

Quita el elemento con la clave especificada del objeto IDictionary.

Espacio de nombres: System.Collections
Ensamblado: mscorlib (en mscorlib.dll)

Sintaxis

Visual Basic (Declaración)
Sub Remove ( _
    key As Object _
)
Visual Basic (Uso)
Dim instance As IDictionary
Dim key As Object

instance.Remove(key)
C#
void Remove (
    Object key
)
C++
void Remove (
    Object^ key
)
J#
void Remove (
    Object key
)
JScript
function Remove (
    key : Object
)

Parámetros

key

Clave del elemento que se va a quitar.

Excepciones

Tipo de excepciónCondición

ArgumentNullException

El valor de key es referencia de objeto null (Nothing en Visual Basic).

NotSupportedException

El objeto IDictionary es de sólo lectura.

O bien

IDictionary tiene un tamaño fijo.

Comentarios

Si el objeto IDictionary no contiene un elemento con la clave especificada, IDictionary no sufre ningún cambio. No se produce ninguna excepción.

Ejemplo

En el ejemplo de código siguiente se muestra cómo implementar el método Remove. Este ejemplo de código forma parte de un ejemplo más amplio referente a la clase IDictionary.

Visual Basic
Public Sub Remove(ByVal key As Object) Implements IDictionary.Remove
    If key = Nothing Then
        Throw New ArgumentNullException("key")
    End If
    ' Try to find the key in the DictionaryEntry array
    Dim index As Integer
    If TryGetIndexOfKey(key, index) Then

        ' If the key is found, slide all the items up.
        Array.Copy(items, index + 1, items, index, (ItemsInUse - index) - 1)
        ItemsInUse = ItemsInUse - 1
    Else

        ' If the key is not in the dictionary, just return. 
    End If
End Sub
C#
public void Remove(object key)
{
    if (key == null) throw new ArgumentNullException("key");
    // Try to find the key in the DictionaryEntry array
    Int32 index;
    if (TryGetIndexOfKey(key, out index))
    {
        // If the key is found, slide all the items up.
        Array.Copy(items, index + 1, items, index, ItemsInUse - index - 1);
        ItemsInUse--;
    } 
    else
    {
        // If the key is not in the dictionary, just return. 
    }
}
C++
public:
    virtual void Remove(Object^ key)
    {
        if (key == nullptr)
        {
            throw gcnew ArgumentNullException("key");
        }
        // Try to find the key in the DictionaryEntry array
        int index;
        if (TryGetIndexOfKey(key, &index))
        {
            // If the key is found, slide all the items down.
            Array::Copy(items, index + 1, items, index, itemsInUse -
                index - 1);
            itemsInUse--;
        }
        else
        {
            // If the key is not in the dictionary, just return.
            return;
        }
    }
Plataformas

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium, Windows Mobile para Pocket PC, Windows Mobile para Smartphone, Windows Server 2003, Windows XP Media Center, Windows XP Professional x64, Windows XP SP2, Windows XP Starter Edition

.NET Framework no admite todas las versiones de cada plataforma. Para obtener una lista de las versiones admitidas, vea Requisitos del sistema.

Información de versión

.NET Framework

Compatible con: 2.0, 1.1, 1.0

.NET Compact Framework

Compatible con: 2.0, 1.0
Vea también

Etiquetas :


Page view tracker