Hashtable
In computing, a hash table (hash map) is a data structure which implements an associative array abstract data type, a structure that can map keys to values. A hash table uses a hash function to compute an index into an array of buckets or slots, from which the desired value can be found.
Explore My Other Channel for More Cool and Valuable Insights
👉 Youtube Learn Tech Tips👉 Tiktok
👉 Facebook:Dictionary
A dictionary uses a key to reference the value directly inside of an associative array.
In computer science, an associative array, map, symbol table, or dictionary is an abstract data type composed of a collection of (key, value) pairs, such that each possible key appears at most once in the collection.Now, what differences between Hashtable and Dictionary
Dictionary:
- It returns/throws Exception if we try to find a key which does not exist.
- It is faster than a Hashtable because there is no boxing and unboxing.
- Only public static members are thread safe.
- Dictionary is a generic type which means we can use it with any
data type (When creating, must specify the data types for both keys and
values).
Example:Dictionary<string, string> <NameOfDictionaryVar> = new Dictionary<string, string>();
- Dictionay is a type-safe implementation of Hashtable,
Keys
andValues
are strongly typed.
- It returns null if we try to find a key which does not exist.
- It is slower than dictionary because it requires boxing and unboxing.
- All the members in a Hashtable are thread safe,
- Hashtable is not a generic type,
- Hashtable is loosely-typed data structure, we can add keys and values of any type.
Thank you for reading this post. I hope you found it helpful and easy to follow. If you have any feedback or questions about
Comparing Hashtable and Dictionary in C# ,
please share them in the comments below. I would love to hear from you and discuss this topic further
✋✋✋✋
Webzone Tech Tips, all things Tech Tips for web development
- I am Zidane, See you next time soon ✋✋✋✋