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
下面的代码示例演示如何使用
Remove
方法从字典中删除键/值对。
此代码示例是为
Dictionary<TKey,TValue>
类提供的更大示例的一部分, (
openWith
是此示例中使用的字典的名称) 。
// 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("\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
Dictionary<TKey,TValue>
如果 不包含具有指定键的元素,则
Dictionary<TKey,TValue>
保持不变。 不会引发异常。
此方法接近 O (1) 操作。
仅限 .NET Core 3.0+:可以安全地调用此可变方法,而不会使实例上的
Dictionary<TKey,TValue>
活动枚举器失效。 这并不意味着线程安全。
public:
bool Remove(TKey key, [Runtime::InteropServices::Out] TValue % value);
public bool Remove (TKey key, out TValue value);
member this.Remove : 'Key * 'Value -> bool
Public Function Remove (key As TKey, ByRef value As TValue) As Boolean