Different between HashTable, Dictionary and ConcurrentDictionary

This will discuss the Different between HashTable, Dictionary and ConcurrentDictionary in .NET environment.

HashTable store the element as Object (loose) type that required boxing and unboxing when you store or retrieve a value type. This would recommend when you have more than one object type that required to store in the same memory.


Hashtable ht = new Hashtable();

ht.Add("Integer", (int)16);
ht.Add("String", "hashTable");
ht.Add("Long",(long)18);

Dictionary work same way as HashTable but with a specific (strong) type (other than Object) value which provides better performance than a Hashtable for value types.


Dictionary dic = new Dictionary();

dic.Add("my", "Malaysia");
dic.Add("ca", "Canada");
dic.Add("in", "India");
dic.Add("cn", "China");

ConcurrentDictionary also work same way as Dictionary and should be used when multiple threads might be accessing the collection simultaneously.