Why is Dictionary preferred over Hashtable in C#?

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

    HashTable:

    Key/value will be converted into an object (boxing) type while storing into the heap.

    Key/value needs to be converted into the desired type while reading from the heap.

    These operations are very costly. We need to avoid boxing/unboxing as much as possible.

    Dictionary : Generic variant of HashTable.

    No boxing/unboxing. No conversions required.

提交回复
热议问题