Why is Dictionary preferred over Hashtable in C#?

后端 未结 19 1518
长情又很酷
长情又很酷 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:44

    Since .NET Framework 3.5 there is also a HashSet which provides all the pros of the Dictionary if you need only the keys and no values.

    So if you use a Dictionary and always set the value to null to simulate the type safe hash table you should maybe consider switching to the HashSet.

提交回复
热议问题