Język

SortedDictionary<TKey,TValue>.Remove(TKey) Metoda

Definicja

Usuwa element z określonym kluczem z .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

Parametry

key
TKey

Klucz elementu do usunięcia.

Zwraca

true jeśli element został pomyślnie usunięty; w przeciwnym razie, false. Ta metoda zwraca false również wartość , jeśli key nie zostanie znaleziona w elemecie SortedDictionary<TKey,TValue>.

Implementuje

Wyjątki

Parametr key ma wartość null.

Przykłady

Poniższy przykład kodu pokazuje, jak usunąć parę klucz/wartość ze słownika Remove przy użyciu metody .

Ten przykład kodu jest częścią większego przykładu udostępnionego dla klasy 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

Uwagi

Jeśli element SortedDictionary<TKey,TValue> nie zawiera elementu z określonym kluczem, SortedDictionary<TKey,TValue> pozostaje niezmieniony. Nie jest zgłaszany żaden wyjątek.

Ta metoda jest operacją O(log n).

Dotyczy

Zobacz też