Check if OrderedDictionary collection contains a specific key in CSharp

Description

The following code shows how to check if OrderedDictionary collection contains a specific key.

Example


using System;// www  .  j av  a  2  s.co  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");

        if (myOrderedDictionary.Contains("testKey3"))
        {
            myOrderedDictionary.Remove("testKey3");
        }
        
        Console.WriteLine(myOrderedDictionary.Contains("testKey3"));
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Collections »




ArrayList
BitArray
Collection
Comparer
HashSet
Hashtable
LinkedList
List
ListDictionary
OrderedDictionary
Queue
SortedList
SortedSet
Stack
StringCollection
StringDictionary