C# OrderedDictionary Remove
Description
OrderedDictionary Remove
removes the entry with the
specified key from the OrderedDictionary collection.
Syntax
OrderedDictionary.Remove
has the following syntax.
public void Remove(
Object key
)
Parameters
OrderedDictionary.Remove
has the following parameters.
key
- The key of the entry to remove.
Returns
OrderedDictionary.Remove
method returns
Example
using System;/* w w w . j a va 2 s . c o m*/
using System.Collections;
using System.Collections.Specialized;
public class SamplesStringCollection {
public static void Main() {
OrderedDictionary myOrderedDictionary = new OrderedDictionary();
myOrderedDictionary.Add("testKey1", "testValue1");
myOrderedDictionary.Add("testKey2", "testValue2");
myOrderedDictionary.Add("testKey3", "testValue3");
myOrderedDictionary.Insert(0, "insertedKey1", "insertedValue1");
// Modify the value of the entry with the key "testKey2"
myOrderedDictionary["testKey2"] = "modifiedValue";
// Remove the last entry from the OrderedDictionary: "testKey3"
myOrderedDictionary.RemoveAt(myOrderedDictionary.Count - 1);
// Remove the "keyToDelete" entry, if it exists
if (myOrderedDictionary.Contains("keyToDelete"))
{
myOrderedDictionary.Remove("keyToDelete");
}
}
}