Quita el elemento con la clave especificada del objeto
IDictionary.
Espacio de nombres: System.Collections
Ensamblado: mscorlib (en mscorlib.dll)
Visual Basic (Declaración)
Sub Remove ( _
key As Object _
)
Dim instance As IDictionary
Dim key As Object
instance.Remove(key)
void Remove (
Object key
)
void Remove (
Object^ key
)
void Remove (
Object key
)
function Remove (
key : Object
)
Parámetros
- key
Clave del elemento que se va a quitar.
| Tipo de excepción | Condició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. |
Si el objeto IDictionary no contiene un elemento con la clave especificada, IDictionary no sufre ningún cambio. No se produce ninguna excepción.
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.
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
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.
}
}
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;
}
}
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.
.NET Framework
Compatible con: 2.0, 1.1, 1.0
.NET Compact Framework
Compatible con: 2.0, 1.0