- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- 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
Hashtable vs. Dictionary in C#
Hashtable
A hash table is used when you need to access elements by using key, and you can identify a useful key value. Each item in the hash table has a key/value pair. The key is used to access the items in the collection.
The members in a Hashtable are thread safe. It returns null if we try to find a key that does not exist. Hashtable is not a generic type.
The Hashtable collection is slower than dictionary because it requires boxing and unboxing.
To declare a Hashtable −
Hashtable ht = new Hashtable();
Dictionary
Dictionary is a collection of keys and values in C#. Dictionary is included in the System.Collection.Generics namespace. Dictionary is a generic type and returns an error if you try to find a key which is not there.
The Dictionary collection is faster than Hashtable because there is no boxing and unboxing.
To declare a Dictionary −
IDictionary<int, string> d = new Dictionary<int, string>();