- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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#
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 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>();
- Working with Hashtable and Dictionary in C#
- Difference between Dictionary and Hashtable in C#
- Difference between HashTable and Dictionary in C#
- List vs tuple vs dictionary in Python
- How to convert Dictionary to Hashtable in PowerShell?
- Why is a Dictionary preferred over a Hashtable in C#?
- What is the difference between Dictionary and HashTable in PowerShell?
- Hashtable in Java
- Check if a Hashtable is equal to another Hashtable in C#
- Clear a Hashtable in C#
- Virtual vs Sealed vs New vs Abstract in C#
- Convert string dictionary to dictionary in Python
- Difference between HashMap and HashTable in Java.
- Differences between HashMap and Hashtable in Java