开发者

Both Hash tables and dictionary in C#. What is the diffence [duplicate]

开发者 https://www.devze.com 2023-01-30 12:54 出处:网络
This question already has answers here: 开发者_StackOverflow中文版 Closed 12 years ago. Possible Duplicate:
This question already has answers here: 开发者_StackOverflow中文版 Closed 12 years ago.

Possible Duplicate:

Why Dictionary is preferred over hashtable in C#?

Hi, I noticed that we have both a hashtable implementation and a dictionary implementation in C#. but, isn't a hashtable a way of implementing a dictionary. Then, why provide both? Dont they do the same thing.


Already answered here on StackOverFlow

The best answer was from Michael Madsen : Dictionary is a generic type, Hashtable is not. That means you get type safety with Dictionary, because you can't insert any random object into it, and you don't have to cast the values you take out.


Dictionary is a Generic Type , Hashtable is not


Type Conversion

1- Hashtable is a non generic key value collection and requires run time type conversion.

2- Dictionary is a generic key value collection and does not require run time type conversion.

Collision Avoidence

1- Hashtable uses Double Hashing to Collisions avoidance technique.

2- Dictionary uses Chaining for avoidence.

See Here At MSDN

0

精彩评论

暂无评论...
验证码 换一张
取 消