为什么字典优先于哈希表? [英] Why is Dictionary preferred over hashtable?

查看:153
本文介绍了为什么字典优先于哈希表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在大多数编程语言中,字典优先于哈希表。
这是什么原因?

解决方案

为什么值得,字典一个哈希表。



如果你的意思是为什么我们使用Dictionary类而不是Hashtable类?,那么这是一个简单的答案:Dictionary是一个通用类型,哈希表不是。这意味着您可以使用字典获取类型安全性,因为您无法将任何随机对象插入到其中,并且您不需要投出您所需的值。


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

解决方案

For what it's worth, a Dictionary is a hash table.

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.

这篇关于为什么字典优先于哈希表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆