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(ログ n) 操作です。

適用対象

こちらもご覧ください