Dictionary<TKey,TValue>.Remove Dictionary<TKey,TValue>.Remove Dictionary<TKey,TValue>.Remove Dictionary<TKey,TValue>.Remove Method

Définition

Surcharges

Remove(TKey) Remove(TKey) Remove(TKey) Remove(TKey)

Supprime de Dictionary<TKey,TValue> la valeur ayant la clé spécifiée.Removes the value with the specified key from the Dictionary<TKey,TValue>.

Remove(TKey, TValue) Remove(TKey, TValue) Remove(TKey, TValue) Remove(TKey, TValue)

Remove(TKey) Remove(TKey) Remove(TKey) Remove(TKey)

Supprime de Dictionary<TKey,TValue> la valeur ayant la clé spécifiée.Removes the value with the specified key from the Dictionary<TKey,TValue>.

public:
 virtual bool Remove(TKey key);
public bool Remove (TKey key);
abstract member Remove : 'Key -> bool
override this.Remove : 'Key -> bool
Public Function Remove (key As TKey) As Boolean

Paramètres

key
TKey TKey TKey TKey

Clé de l'élément à supprimer.The key of the element to remove.

Retours

true si la recherche et la suppression de l'élément réussissent ; sinon, false.true if the element is successfully found and removed; otherwise, false. Cette méthode retourne false si key est introuvable dans Dictionary<TKey,TValue>.This method returns false if key is not found in the Dictionary<TKey,TValue>.

Implémente

Exceptions

Exemples

L’exemple de code suivant montre comment supprimer une paire clé/valeur d’un dictionnaire à l' Remove aide de la méthode.The following code example shows how to remove a key/value pair from a dictionary using the Remove method.

Cet exemple de code fait partie d’un exemple plus complet fourni Dictionary<TKey,TValue> pour laopenWith classe (est le nom du dictionnaire utilisé dans cet exemple).This code example is part of a larger example provided for the Dictionary<TKey,TValue> class (openWith is the name of the Dictionary used in this example).

// 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

Remarques

Si ne contient pas d’élément avec la clé spécifiée, le Dictionary<TKey,TValue> reste inchangé. Dictionary<TKey,TValue>If the Dictionary<TKey,TValue> does not contain an element with the specified key, the Dictionary<TKey,TValue> remains unchanged. Aucune exception n'est levée.No exception is thrown.

Cette méthode s’approche d’une opération O (1).This method approaches an O(1) operation.

Voir aussi

Remove(TKey, TValue) Remove(TKey, TValue) Remove(TKey, TValue) Remove(TKey, TValue)

public:
 bool Remove(TKey key, [Runtime::InteropServices::Out] TValue % value);
public bool Remove (TKey key, out TValue value);
member this.Remove : 'Key *  -> bool
Public Function Remove (key As TKey, ByRef value As TValue) As Boolean

Paramètres

key
TKey TKey TKey TKey
value
TValue TValue TValue TValue

Retours

S’applique à