This documentation is archived and is not being maintained.

IDictionary.Remove Method

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

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

Sub Remove ( _
	key As Object _
Dim instance As IDictionary 
Dim key As Object



Type: System.Object

The key of the element to remove.


key is Nothing.


The IDictionary object is read-only.


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 Sub Remove(ByVal key As Object) Implements IDictionary.Remove
    If key = Nothing Then 
        Throw New ArgumentNullException("key")
    End If 
    ' Try to find the key in the DictionaryEntry array 
    Dim index As Integer 
    If TryGetIndexOfKey(key, index) Then 

        ' If the key is found, slide all the items up.
        Array.Copy(items, index + 1, items, index, (ItemsInUse - index) - 1)
        ItemsInUse = ItemsInUse - 1

        ' If the key is not in the dictionary, just return.  
    End If 
End Sub

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

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

.NET Framework

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

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0