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

定义

从 中移除具有指定键的 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

要删除的元素的键。

返回

true 如果已成功删除元素,则为 ;否则,为 false. 此方法还会返回false在原始key文件中找不到时SortedList<TKey,TValue>

实现

例外

keynull

示例

下面的代码示例演示如何使用 Remove 该方法从排序列表中删除键/值对。

该代码示例是 SortedList<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
// Use the Remove method to remove a key/value pair.
printfn "\nRemove(\"doc\")"
openWith.Remove("doc") |> ignore

if not (openWith.ContainsKey("doc")) then
    printfn "Key \"doc\" is not found."

注解

此方法执行二进制搜索;但是,元素向上移动以填充开放点,因此此方法是 O(n) 操作,其中nCount

适用于

另请参阅