StringDictionary.Remove Method (String)

 

Removes the entry with the specified key from the string dictionary.

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

Public Overridable Sub Remove (
	key As String
)

Parameters

key
Type: System.String

The key of the entry to remove.

Exception Condition
ArgumentNullException

The key is null.

NotSupportedException

The StringDictionary is read-only.

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

The key is handled in a case-insensitive manner; it is translated to lowercase before it is used to find the entry to remove from the string dictionary.

This method is an O(1) operation.

The following code example demonstrates how to add and remove elements from a StringDictionary.

Imports System
Imports System.Collections
Imports System.Collections.Specialized

Public Class SamplesStringDictionary   

   Public Shared Sub Main()

      ' Creates and initializes a new StringDictionary.
      Dim myCol As New StringDictionary()
      myCol.Add("red", "rojo")
      myCol.Add("green", "verde")
      myCol.Add("blue", "azul")

      ' Displays the values in the StringDictionary.
      Console.WriteLine("Initial contents of the StringDictionary:")
      PrintKeysAndValues(myCol)

      ' Deletes an element.
      myCol.Remove("green")
      Console.WriteLine("The collection contains the following elements after removing ""green"":")
      PrintKeysAndValues(myCol)

      ' Clears the entire collection.
      myCol.Clear()
      Console.WriteLine("The collection contains the following elements after it is cleared:")
      PrintKeysAndValues(myCol)

   End Sub 'Main

   Public Shared Sub PrintKeysAndValues(myCol As StringDictionary)
      Dim de As DictionaryEntry

      Console.WriteLine("   KEY        VALUE")
      For Each de In  myCol
         Console.WriteLine("   {0,-10} {1}", de.Key, de.Value)
      Next de
      Console.WriteLine()

   End Sub 'PrintKeysAndValues

End Class 'SamplesStringDictionary 


'This code produces the following output.
'
'Initial contents of the StringDictionary:
'   KEY        VALUE
'   green      verde
'   red        rojo
'   blue       azul
'
'The collection contains the following elements after removing "green":
'   KEY        VALUE
'   red        rojo
'   blue       azul
'
'The collection contains the following elements after it is cleared:
'   KEY        VALUE
'

Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
Return to top
Show: