Why is a Dictionary preferred over a Hashtable in C#?

ProgrammingServer Side ProgrammingCsharp

Hashtable class represents a collection of key-and-value pairs that are organized based on the hash code of the key. It uses the key to access the elements in the collection.

Dictionary is a collection of keys and values in C#. Dictionary<TKey, TValue> is included in the System.Collection.Generics namespace.

Hashtable is slower than Dictionary. For strongly-typed collections, the Dictionary collection is faster.

Let’s say we need to find a key from Hashtable collections. With that, we are also finding a key from Dictionary collection as well. In that case, Dictionary would be faster for the same statement −

For HashTable


For Dictionary

Updated on 22-Jun-2020 15:36:35