語言

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>。

實作

例外狀況

key 是 null。

範例

以下程式碼範例展示了如何使用此 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) 運算,其中 n 為 Count。

適用於

另請參閱