Remove Method

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

 

Removes the element with the specified key from the SortedDictionary<TKey, TValue>.

Namespace:   System.Collections.Generic
Assembly:  System (in System.dll)

public bool Remove(
	TKey key
)

Parameters

key
Type: TKey

The key of the element to remove.

Return Value

Type: System.Boolean

true if the element is successfully removed; otherwise, false. This method also returns false if key is not found in the SortedDictionary<TKey, TValue>.

Exception Condition
ArgumentNullException

key is null.

If the SortedDictionary<TKey, TValue> does not contain an element with the specified key, the SortedDictionary<TKey, TValue> remains unchanged. No exception is thrown.

This method is an O(log n) operation.

The following code example shows how to remove a key/value pair from the dictionary using the Remove method.

This code example is part of a larger example provided for the SortedDictionary<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.");
}

Universal Windows Platform
Available since 8
.NET Framework
Available since 2.0
Portable Class Library
Supported in: portable .NET platforms
Windows Phone Silverlight
Available since 8.0
Windows Phone
Available since 8.1
Return to top
Show:
© 2016 Microsoft