Home >Backend Development >C#.Net Tutorial >Why are dictionaries preferred over hash tables in C#?
The Hashtable class represents a collection of key-value pairs organized according to the hash code of the key. It uses keys to access elements in the collection.
A dictionary is a collection of keys and values in C#. Dictionary
Hashtable is slower than Dictionary. For strongly typed collections, Dictionary collections are faster.
Suppose we need to find a key from a Hashtable collection. This way, we can also find a key from the Dictionary collection. In this case, for the same statement, dictionary will be faster -
hashtable.ContainsKey("12345");
dictionary.ContainsKey("12345")
The above is the detailed content of Why are dictionaries preferred over hash tables in C#?. For more information, please follow other related articles on the PHP Chinese website!