为什么词典preferred在哈希表?词典、preferred、哈希表

2023-09-02 10:12:30 作者:男Ren哭泣,不代表软弱

在大多数编程语言,词典是pferred在哈希表$ P $。 什么是背后的原因是什么?

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

推荐答案

FWIW,一个字典是一个哈希表。

FWIW, a Dictionary is a hash table.

如果你的意思是?为什么我们使用Hashtable类的字典类,而不是,那么这是一个简单的答案:字典是一个泛型类型,哈希表是没有的。这意味着你得到的类型安全与字典,因为你不能插入任何随机对象到它,你没有投你拿出的值。

If you meant "why do we use the Dictionary class instead of the Hashtable class?", then it's an easy answer: 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.