SortedDictionary<TKey,TValue>.Remove(TKey) メソッド

定義

指定したキーを持つ要素を SortedDictionary<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。 このメソッドは、falsekey に見つからない場合にも SortedDictionary<TKey,TValue> を返します。

実装

例外

keynullです。

次のコード例は、 メソッドを使用してディクショナリからキーと値のペアを削除する方法を Remove 示しています。

このコード例は、SortedDictionary<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

注釈

SortedDictionary<TKey,TValue> 指定したキーを持つ要素が含まれていない場合、 SortedDictionary<TKey,TValue> は変更されません。 例外はスローされません。

このメソッドは O(log n) 操作です。

適用対象

こちらもご覧ください