PropertyCollection.IDictionary.Remove(Object) メソッド

定義

指定したキーを持つ要素を IDictionary オブジェクトから削除します。

 virtual void System.Collections.IDictionary.Remove(System::Object ^ key) = System::Collections::IDictionary::Remove;
void IDictionary.Remove (object key);
abstract member System.Collections.IDictionary.Remove : obj -> unit
override this.System.Collections.IDictionary.Remove : obj -> unit
Sub Remove (key As Object) Implements IDictionary.Remove

パラメーター

key
Object

削除する要素のキー。

実装

例外

keynullです。

IDictionary が読み取り専用です。

次の例は、Remove メソッドを実装する方法を示しています。 このコード例は、IDictionary クラスのために提供されている大規模な例の一部です。

public:
    virtual void Remove(Object^ key)
    {
        if (key == nullptr)
        {
            throw gcnew ArgumentNullException("key");
        }
        // Try to find the key in the DictionaryEntry array
        int index;
        if (TryGetIndexOfKey(key, &index))
        {
            // If the key is found, slide all the items down.
            Array::Copy(items, index + 1, items, index, itemsInUse -
                index - 1);
            itemsInUse--;
        }
        else
        {
            // If the key is not in the dictionary, just return.
            return;
        }
    }
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

適用対象