SortedList<TKey,TValue>.Remove(TKey) 方法
定义
从 SortedList<TKey,TValue> 中移除带有指定键的元素。Removes the element with the specified key from the SortedList<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
要移除的元素的键。The key of the element to remove.
返回
如果该元素已成功移除,则为 true
;否则为 false
。true
if the element is successfully removed; otherwise, false
. 如果在原始 false
中没有找到 key
,此方法也会返回 SortedList<TKey,TValue>。This method also returns false
if key
was not found in the original SortedList<TKey,TValue>.
实现
例外
key
为 null
。key
is null
.
示例
下面的代码示例演示如何使用方法从排序列表中移除键/值对 Remove 。The following code example shows how to remove a key/value pair from the sorted list using the Remove method.
此代码示例是为类提供的更大示例的一部分 SortedList<TKey,TValue> 。This code example is part of a larger example provided for the SortedList<TKey,TValue> class.
// 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
注解
此方法执行二进制搜索;但是,元素将上移以填充打开的位置,因此,此方法是 O (n
) 操作,其中 n
是 Count 。This method performs a binary search; however, the elements are moved up to fill in the open spot, so this method is an O(n
) operation, where n
is Count.