IDictionary.Remove(Object) Methode

Definition

Entfernt das Element mit dem angegebenen Schlüssel aus dem IDictionary Objekt.

public:
 void Remove(System::Object ^ key);
public void Remove(object key);
abstract member Remove : obj -> unit
Public Sub Remove (key As Object)

Parameter

key
Object

Der Schlüssel des zu entfernenden Elements.

Ausnahmen

key ist null.

Das IDictionary Objekt ist schreibgeschützt.

-oder-

Die IDictionary Größe hat eine feste Größe.

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie die Remove Methode implementiert wird. Dieses Codebeispiel ist Teil eines größeren Beispiels, das für die IDictionary Klasse bereitgestellt wird.

public void Remove(object key)
{
    if (key == null) throw new ArgumentNullException("key");
    // Try to find the key in the DictionaryEntry array
    Int32 index;
    if (TryGetIndexOfKey(key, out index))
    {
        // If the key is found, slide all the items up.
        Array.Copy(items, index + 1, items, index, ItemsInUse - index - 1);
        ItemsInUse--;
    }
    else
    {
        // If the key is not in the dictionary, just return.
    }
}
Public Sub Remove(ByVal key As Object) Implements IDictionary.Remove
    If key = Nothing Then
        Throw New ArgumentNullException("key")
    End If
    ' Try to find the key in the DictionaryEntry array
    Dim index As Integer
    If TryGetIndexOfKey(key, index) Then

        ' If the key is found, slide all the items up.
        Array.Copy(items, index + 1, items, index, (ItemsInUse - index) - 1)
        ItemsInUse = ItemsInUse - 1
    Else

        ' If the key is not in the dictionary, just return. 
    End If
End Sub

Hinweise

Wenn das IDictionary Objekt kein Element mit dem angegebenen Schlüssel enthält, bleibt dies IDictionary unverändert. Es wird keine Ausnahme ausgelöst.

Gilt für: