SortedDictionary<TKey,TValue>.Remove(TKey) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
從 中移除具有指定鍵的 SortedDictionary<TKey,TValue>元素。
public:
virtual bool Remove(TKey key);
public bool Remove(TKey key);
abstract member Remove : 'Key -> bool
override this.Remove : 'Key -> bool
Public Function Remove (key As TKey) As Boolean
參數
- key
- TKey
關鍵是元素要移除。
傳回
true如果元素被成功移除;否則,。 false 若 false 未在 中,key此方法也會回傳SortedDictionary<TKey,TValue>。
實作
例外狀況
key 是 null。
範例
以下程式碼範例說明如何使用此 Remove 方法從字典中移除鍵值對。
此程式碼範例是本類別更大範例 SortedDictionary<TKey,TValue> 的一部分。
// Use the Remove method to remove a key/value pair.
Console.WriteLine("\nRemove(\"doc\")");
openWith.Remove("doc");
if (!openWith.ContainsKey("doc"))
{
Console.WriteLine("Key \"doc\" is not found.");
}
' Use the Remove method to remove a key/value pair.
Console.WriteLine(vbLf + "Remove(""doc"")")
openWith.Remove("doc")
If Not openWith.ContainsKey("doc") Then
Console.WriteLine("Key ""doc"" is not found.")
End If
備註
若 不 SortedDictionary<TKey,TValue> 包含指定鍵的元素,則 SortedDictionary<TKey,TValue> 保持不變。 沒例外拋出。
此方法為 O(log n) 操作。