IDictionary<TKey,TValue>.Remove(TKey) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
從 中移除具有指定鍵的 IDictionary<TKey,TValue>元素。
public:
bool Remove(TKey key);
public bool Remove(TKey key);
abstract member Remove : 'Key -> bool
Public Function Remove (key As TKey) As Boolean
參數
- key
- TKey
關鍵是元素要移除。
傳回
true如果元素被成功移除;否則,。 false 若false原始 中找不到 key,此方法也會回傳IDictionary<TKey,TValue>。
例外狀況
key 是 null。
範例
以下程式碼範例展示了如何使用此 Remove 方法從字典中移除鍵值對。
這些程式碼是更大範例的一部分,可以編譯並執行。 參見 System.Collections.Generic.IDictionary<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
備註
實作方式在決定物件相等的方式上可能有所不同;例如,類別 List<T> 使用 Comparer<T>.Default,而類別 Dictionary<TKey,TValue> 則允許使用者指定 IComparer<T> 用於比較鍵的實作。