Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

IDictionary.Remove Method

Removes the element with the specified key from the IDictionary object.

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

void Remove(
	Object key
)

Parameters

key
Type: System.Object
The key of the element to remove.

ExceptionCondition
ArgumentNullException

key is null.

NotSupportedException

The IDictionary object is read-only.

-or-

The IDictionary has a fixed size.

If the IDictionary object does not contain an element with the specified key, the IDictionary remains unchanged. No exception is thrown.

The following code example demonstrates how to implement the Remove method. This code example is part of a larger example provided for the IDictionary class.


public void Remove(object key)
{
    if (key == null) throw new ArgumentNullException("key");
    // Try to find the key in the DictionaryEntry array
    Int32 index;
    if (TryGetIndexOfKey(key, out index))
    {
        // If the key is found, slide all the items up.
        Array.Copy(items, index + 1, items, index, ItemsInUse - index - 1);
        ItemsInUse--;
    } 
    else
    {
        // If the key is not in the dictionary, just return. 
    }
}


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

Show:
© 2014 Microsoft