Hashtable vs Dictionary

HashTable

1. When Declaring Hashtable we do not need to specify data types key/values.

2. We can store key/value pair of same type or different types at run time.

3. Since there is no strong typing during compile time, every time we retrieve value it has to perform boxing/unboxing, hence there is performance impact and process becomes slow.

4. In Hashtable, if you try to access a key that doesn’t present in the given Hashtable, then it will give null values.

5. It is thread safe.

6. It doesn’t maintain the order of stored values.

Dictionary

1. At the time of declaration we have to specify types for key/value.

2. We have to store key/value of same type as defined during declaration (compile time). You get type safety with Dictionary<TKey, TValue>

3. The data retrieval is faster than Hashtable due to no boxing/ unboxing.

4. In Dictionary, if you try to access a key that doesn’t present in the given Dictionary, then it will give error.

5. It is also thread safe but only for public static members.

6. It always maintain the order of stored values.