Why is Dictionary preferred over Hashtable in C#?

后端 未结 19 1240
长情又很酷
长情又很酷 2020-11-22 05:53

In most programming languages, dictionaries are preferred over hashtables. What are the reasons behind that?

19条回答
  •  既然无缘
    2020-11-22 06:39

    Notice that MSDN says: "Dictionary<(Of <(TKey, TValue>)>) class is implemented as a hash table", not "Dictionary<(Of <(TKey, TValue>)>) class is implemented as a HashTable"

    Dictionary is NOT implemented as a HashTable, but it is implemented following the concept of a hash table. The implementation is unrelated to the HashTable class because of the use of Generics, although internally Microsoft could have used the same code and replaced the symbols of type Object with TKey and TValue.

    In .NET 1.0 Generics did not exist; this is where the HashTable and ArrayList originally began.

提交回复
热议问题