IDictionary<TKey,TValue>.Remove(TKey) Método
Definición
Quita el elemento con la clave especificada de IDictionary<TKey,TValue>.Removes the element with the specified key from the IDictionary<TKey,TValue>.
public:
bool Remove(TKey key);
public bool Remove (TKey key);
abstract member Remove : 'Key -> bool
Public Function Remove (key As TKey) As Boolean
Parámetros
- key
- TKey
Clave del elemento que se va a quitar.The key of the element to remove.
Devoluciones
Es true
si el elemento se quita correctamente; en caso contrario, es false
.true
if the element is successfully removed; otherwise, false
. Este método también devuelve false
si no se encontró key
en el objeto IDictionary<TKey,TValue> original.This method also returns false
if key
was not found in the original IDictionary<TKey,TValue>.
Excepciones
key
es null
.key
is null
.
IDictionary<TKey,TValue> es de solo lectura.The IDictionary<TKey,TValue> is read-only.
Ejemplos
En el ejemplo de código siguiente se muestra cómo quitar un par clave-valor de un diccionario mediante el Remove método.The following code example shows how to remove a key/value pair from a dictionary using the Remove method.
Este código forma parte de un ejemplo más grande que se puede compilar y ejecutar.This code is part of a larger example that can be compiled and executed. Vea System.Collections.Generic.IDictionary<TKey,TValue>.See System.Collections.Generic.IDictionary<TKey,TValue>.
// Use the Remove method to remove a key/value pair.
Console::WriteLine("\nRemove(\"doc\")");
openWith->Remove("doc");
if (!openWith->ContainsKey("doc"))
{
Console::WriteLine("Key \"doc\" is not found.");
}
// Use the Remove method to remove a key/value pair.
Console.WriteLine("\nRemove(\"doc\")");
openWith.Remove("doc");
if (!openWith.ContainsKey("doc"))
{
Console.WriteLine("Key \"doc\" is not found.");
}
' Use the Remove method to remove a key/value pair.
Console.WriteLine(vbLf + "Remove(""doc"")")
openWith.Remove("doc")
If Not openWith.ContainsKey("doc") Then
Console.WriteLine("Key ""doc"" is not found.")
End If
Comentarios
Las implementaciones pueden variar en la forma en que determinan la igualdad de objetos; por ejemplo, la List<T> clase utiliza Comparer<T>.Default , mientras que la Dictionary<TKey,TValue> clase permite al usuario especificar la IComparer<T> implementación que se va a utilizar para comparar las claves.Implementations can vary in how they determine equality of objects; for example, the List<T> class uses Comparer<T>.Default, whereas the Dictionary<TKey,TValue> class allows the user to specify the IComparer<T> implementation to use for comparing keys.