Hashtable ht = new Hashtable(); ht.Add("key1","value1"); ht.Add("key2","value2"); ht.Add("key3","value3"); if (ht.ContainsKey("key2")) { Console.WriteLine("Key 'key2' is present in Hashtable."); }
DictionaryThis example creates a Dictionary (which is similar to a Hashtable) and adds three key/value pairs to it. It then checks if the Dictionary contains a specific key ("key4"), and prints a message indicating whether the key is present or not. The package/library for the System.Collections namespace is the .NET Framework Class Library.ht = new Dictionary (); ht.Add("key1",1); ht.Add("key2",2); ht.Add("key3",3); if (ht.ContainsKey("key4")) { Console.WriteLine("Key 'key4' is present in Hashtable."); }