In most programming languages, dictionaries are preferred over hashtables.
What are the reasons behind that?
C# – Why is Dictionary preferred over Hashtable in C#
.netc++data-structuresvb.net
Related Question
- C# – Deep cloning objects
- C# – Should ‘using’ directives be inside or outside the namespace
- C# – What are the correct version numbers for C#
- C# – Case insensitive ‘Contains(string)’
- C# – Returning IEnumerable
vs. IQueryable - Python – How to remove a key from a Python dictionary
- C# – Why not inherit from List
Best Solution
For what it's worth, a Dictionary is (conceptually) a hash table.
If you meant "why do we use the
Dictionary<TKey, TValue>
class instead of theHashtable
class?", then it's an easy answer:Dictionary<TKey, TValue>
is a generic type,Hashtable
is not. That means you get type safety withDictionary<TKey, TValue>
, because you can't insert any random object into it, and you don't have to cast the values you take out.Interestingly, the
Dictionary<TKey, TValue>
implementation in the .NET Framework is based on theHashtable
, as you can tell from this comment in its source code:Source