SortedList<TKey,TValue>.Remove(TKey) SortedList<TKey,TValue>.Remove(TKey) SortedList<TKey,TValue>.Remove(TKey) SortedList<TKey,TValue>.Remove(TKey) Method

定義

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

要移除的項目索引鍵。The key of the element to remove.

傳回

如果成功移除項目,則為 true,否則為 falsetrue if the element is successfully removed; otherwise, false. 如果在原始的 SortedList<TKey,TValue> 中找不到 key,則這個方法也會傳回 falseThis method also returns false if key was not found in the original SortedList<TKey,TValue>.

實作

例外狀況

範例

下列程式碼範例示範如何使用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)運算,其中nCountThis 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.

適用於

另請參閱