This example shows you How to use HashTable in C#.

Hashtable represents a collection of key/value pairs which maps keys to value.

You can easily Add, Remove, Check containing values or keys by using Hashtable methods. Using Hashtable helps you get data quickly with key pair.

Hashtable ht = new Hashtable();
ht.Add("1", "DotNetExample");
ht.Add("abc", new Customer());

You can use the Add method to add an item to the Hashtable.

To Remove an item from the Hashtable you can use the Remove method.


You should check your key before adding a new item to the Hashtable.

   //Add new item or do something

You can also, check the existing value in Hashtable.

   //do something