OrderedDictionary.Remove(Object) メソッド

定義

指定したキーを持つエントリを 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)

パラメーター

key
Object

削除するエントリのキー。

実装

例外

OrderedDictionary コレクションは読み取り専用です。

keynullです。

次のコード例は、 OrderedDictionary コレクションの変更を示しています。 この例では、 Remove メソッドを使用して、キー "keyToDelete" を持つエントリを OrderedDictionaryから削除します。 このコードは、 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

注釈

削除されたエントリの後に続くエントリは、空いた場所を占有するように上に移動し、移動するエントリのインデックスも更新されます。

指定したキーを持つエントリが OrderedDictionary コレクションに含まれていない場合、 OrderedDictionary は変更されず、例外はスローされません。

適用対象