Hi Friends,
What is the difference between hash table and dictionary.why we use hash table and dictionary.
Thanks!
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
SenthilkumarRank #387 · 6.5K reputationPosted Apr 3, 2012, 10:30 PM EDT
The HashTable belongs to the system.Collections namespace and Dictionary belongs to the System.Collections.Generic namesapce and it can be used from C#2.0 above.
both uses the key and value combination. But the Dictionary has some advantages over HashTable.
The dictionary is static typing (and compile-time verification) and uses without boxing and unboxing. It is type specific and strongly typed. It will not throw any error at the run time.
The performance wise it will be good because it does not need the type casting.
For example,
HashTable follows,
Dictionary follows,
MuthuMari MRank #5,738 · 288 reputationPosted Apr 3, 2012, 10:59 PM EDT
Sam HobbsRank #107 · 20.5K reputationPosted Apr 4, 2012, 2:21 PM EDT
That is why the Dictionary is "static typing". The advantages of the Dictionary class that Senthilkumar explains are advantages for all collections in the System.Collections.Generic namespace.
Hash tables were originally created in a time when main memory was much more expensive than it is now; it is probably accurate to say that main memory and disk storage was extremely more expensive. Hash tables can be efficient when the amount of main memory is very limited. Note that the original IBM PC was limted to 1 MB of storage. Most computers now have at least a thousand times more main memory. Hash tables were originally designed long before the original IBM PC existed in a time when memory was more expensive.