OrderedDictionary.Remove(Object) Metoda

Definicja

Usuwa wpis z określonym kluczem z kolekcji 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)

Parametry

key
Object

Klucz wpisu do usunięcia.

Implementuje

Wyjątki

Kolekcja OrderedDictionary jest tylko do odczytu.

key to null.

Przykłady

Poniższy przykład kodu pokazuje modyfikację OrderedDictionary kolekcji. W tym przykładzie Remove metoda służy do usuwania wpisu z kluczem "keyToDelete" z pliku OrderedDictionary. Ten kod jest częścią większego przykładu kodu, który można wyświetlić pod adresem 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 (!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

Uwagi

Wpisy, które następują po usuniętym wpisie, przechodzą w górę, aby zajmować opuszczone miejsce i indeksy wpisów, które się przenoszą, są również aktualizowane.

OrderedDictionary Jeśli kolekcja nie zawiera wpisu z określonym kluczem, OrderedDictionary pozostaje niezmieniona i nie zostanie zgłoszony żaden wyjątek.

Dotyczy