OrderedDictionary.Remove(Object) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
從集合中移除包含指定鍵的 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 合集為唯讀。
key 是 null。
範例
以下程式碼範例示範了集合的 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 則保持不變且不會拋出例外。