Check if the Hashtable contains a specific key in CSharp
Description
The following code shows how to check if the Hashtable contains a specific key.
Example
/*from w w w .j a v a 2 s . co m*/
using System;
using System.Collections;
class MainClass
{
public static void Main()
{
Hashtable myHashtable = new Hashtable();
myHashtable.Add("AL", "Alabama");
myHashtable.Add("CA", "California");
myHashtable.Add("FL", "Florida");
myHashtable.Add("NY", "New York");
myHashtable.Add("WY", "Wyoming");
if (myHashtable.ContainsKey("FL"))
{
Console.WriteLine("myHashtable contains the key FL");
}
}
}
The code above generates the following result.