In most programming languages, dictionaries are preferred over hashtables. What are the reasons behind that?
In most programming languages, dictionaries are preferred over hashtables. What are the reasons behind
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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 theHashtableclass?’, then it’s an easy answer:Dictionary<TKey, TValue>is a generic type,Hashtableis 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