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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
SenthilkumarPosted Apr 4, 2012, 2:30 AM
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,
Sam HobbsPosted Apr 4, 2012, 6:21 PM
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.
MuthuMari MPosted Apr 4, 2012, 2:59 AM