SortedDictionary<TKey,TValue>.Remove(TKey) Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Supprime l’élément avec la clé spécifiée du SortedDictionary<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
Clé de l’élément à supprimer.
Retours
true si l’élément a été supprimé avec succès ; sinon, false. Cette méthode retourne false également si key elle est introuvable dans le SortedDictionary<TKey,TValue>.
Implémente
Exceptions
key a la valeur null.
Exemples
L’exemple de code suivant montre comment supprimer une paire clé/valeur du dictionnaire à l’aide de la Remove méthode.
Cet exemple de code fait partie d’un exemple plus grand fourni pour la SortedDictionary<TKey,TValue> classe.
// 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 le SortedDictionary<TKey,TValue> fichier ne contient pas d’élément avec la clé spécifiée, le SortedDictionary<TKey,TValue> reste inchangé. Aucune exception n’est générée.
Cette méthode est une opération O(log n).