OrderedDictionary.Remove(Object) 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’entrée avec la clé spécifiée de la OrderedDictionary collection.
public:
virtual void Remove(System::Object ^ key);
public void Remove(object key);
abstract member Remove : obj -> unit
override this.Remove : obj -> unit
Public Sub Remove (key As Object)
Paramètres
- key
- Object
Clé de l’entrée à supprimer.
Implémente
Exceptions
La OrderedDictionary collection est en lecture seule.
key a la valeur null.
Exemples
L’exemple de code suivant illustre la modification d’une OrderedDictionary collection. Dans cet exemple, la Remove méthode est utilisée pour supprimer l’entrée avec la clé "keyToDelete" du OrderedDictionary. Ce code fait partie d’un exemple de code plus large qui peut être consulté à l’adresse OrderedDictionary.
// Modifying the OrderedDictionary
if (!myOrderedDictionary.IsReadOnly)
{
// Insert a new key to the beginning of the OrderedDictionary
myOrderedDictionary.Insert(0, "insertedKey1", "insertedValue1");
// Modify the value of the entry with the key "testKey2"
myOrderedDictionary["testKey2"] = "modifiedValue";
// Remove the last entry from the OrderedDictionary: "testKey3"
myOrderedDictionary.RemoveAt(myOrderedDictionary.Count - 1);
// Remove the "keyToDelete" entry, if it exists
if (myOrderedDictionary.Contains("keyToDelete"))
{
myOrderedDictionary.Remove("keyToDelete");
}
}
' Modifying the OrderedDictionary
If Not myOrderedDictionary.IsReadOnly Then
' Insert a new key to the beginning of the OrderedDictionary
myOrderedDictionary.Insert(0, "insertedKey1", "insertedValue1")
' Modify the value of the entry with the key "testKey2"
myOrderedDictionary("testKey2") = "modifiedValue"
' Remove the last entry from the OrderedDictionary: "testKey3"
myOrderedDictionary.RemoveAt(myOrderedDictionary.Count - 1)
' Remove the "keyToDelete" entry, if it exists
If (myOrderedDictionary.Contains("keyToDelete")) Then
myOrderedDictionary.Remove("keyToDelete")
End If
End If
Remarques
Les entrées qui suivent le déplacement de l’entrée supprimée jusqu’à occuper l’emplacement libéré et les index des entrées déplacées sont également mises à jour.
Si la OrderedDictionary collection ne contient pas d’entrée avec la clé spécifiée, elle OrderedDictionary reste inchangée et aucune exception n’est levée.