Interviews4 answers
What is the difference between Dictionary and Hashtable ?
4 Answers
Dictionary is a Generic Type where as HashTable is not
Both Dictionary & HashTable holds the data like key, value as
Mahesh Kumar AlankaPosted Jan 28, 2016, 8:26 PM EST
Dictionary and Hash table are collection of data structure to hold data as key-value pairs.
Dictionary is generic type, hash table is not generic type.
We can't use dictionary with web services.
In .NET hash table is thread safe for use by multiple reader thread and a single writing thread, while in dictionary public static members are thread safe, but any instance members are not guaranteed to be thread safe.
Anil Kumar YadavPosted Apr 30, 2012, 4:45 AM EDT
HashTable takes different datatypes as collection, but Dictionary allows only Specified datatype through out collection.
Lajapathy ArunPosted Apr 28, 2012, 11:53 AM EDT
Dictionary is a generic type, allowing:
static typing (and compile-time verification)
use without boxing
If you are .NET 2.0 or above, you should prefer Dictionary (and the other generic collections)
A subtle but important difference is that Hashtable supports multiple reader threads with a single writer thread, while Dictionary offers no thread safety. If you need thread safety with a generic dictionary, you must implement your own synchronization or (in .NET 4.0) use ConcurrentDictionary.
Dictionary is typed (so valuetypes don't need boxing), a Hashtable isn't (so valuetypes need boxing).
Murali PoolaPosted Apr 23, 2012, 12:49 AM EDT



