- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Difference between HashTable and Dictionary in C#
Both HashTable and Dictionary are the type of data structure which are used to store data. Both of these data structures hold the stored data in key value pair.
On the basis of difference between key features of these we can distinguish between HashTable and Dictionary as follows −
|HashTable is the non-generic type of collection which is used to store data in key/value pair and is defined in System.Collections name space.
|On other hand Dictionary is a generic type collection defined under System.Collection.Generics name space which also store data in the form of key/value pairs.
|In HashTable same or different data type data can be stored as key and value there is no restriction that key and value must of same DataType then only could get stored in the HashTable. Also there is no need to specify the type of the key and value.
|On other hand in case of Dictionary key and value must be of same DataType then only could get stored in dictionary and must specify the type of key and value at the time of creation.
|In case of HashTable the data retrieval is slower due to boxing and unBoxing as compared to that in Dictionary.
|On other hand in case of Dictionary data Retrieval is faster as no boxing and unBoxing is take place in case of Dictionary.
|In case of HashTable null value handled as on access a key that doesn’t present in the given HashTable then null values returned as result.
|On other hand, in case of Dictionary it will give error if try to access a key that doesn’t present in the given Dictionary.
|HashTable does not maintain any order of the inserted key value data.
|On other hand Dictionary maintains the insertion order of stored value.
Kickstart Your Career
Get certified by completing the courseGet Started