OrderedDictionary.Remove(Object) Metodo

Definizione

Rimuove la voce con la chiave specificata dall'insieme OrderedDictionary .

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)

Parametri

key
Object

Chiave della voce da rimuovere.

Implementazioni

Eccezioni

La OrderedDictionary raccolta è di sola lettura.

key è null.

Esempio

Nell'esempio di codice seguente viene illustrata la modifica di una OrderedDictionary raccolta. In questo esempio, il Remove metodo viene usato per rimuovere la voce con la chiave "keyToDelete" da OrderedDictionary. Questo codice fa parte di un esempio di codice più ampio che può essere visualizzato in 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

Commenti

Le voci che seguono la voce rimossa si spostano verso l'alto per occupare la posizione liberata e gli indici delle voci spostate vengono aggiornati anche.

Se la OrderedDictionary raccolta non contiene una voce con la chiave specificata, rimane OrderedDictionary invariata e non viene generata alcuna eccezione.

Si applica a