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("\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

適用於

另請參閱