IDictionary<TKey,TValue>.Remove(TKey) 方法

定义

从 中移除具有指定键的 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在原始IDictionary<TKey,TValue>文件中找不到时key

例外

keynull

示例

下面的代码示例演示如何使用 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>使用,而Dictionary<TKey,TValue>类允许用户指定用于比较键的IComparer<T>Comparer<T>.Default实现。

适用于

另请参阅