Remove Method
Collapse the table of content
Expand the table of content

IDictionary.Remove Method

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

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

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

'Declaration
Sub Remove ( _
	key As Object _
)

Parameters

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

ExceptionCondition
ArgumentNullException

key is Nothing.

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 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
   Else

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


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2016 Microsoft