什么是一个Hashtable的通用版本? [英] What is the Generic version of a Hashtable?
问题描述
我在学习泛型的基础知识和它看起来真的可以提高应用程序的性能。 但是,我不能看到哈希表的一般等价物。 请分享一些示例C#$ C $下创建通用哈希表类。我需要这样一个演示。
I been learning basics of generics and it looks like it can really improve the performance of the application. But, I am not able to see the generic equivalent of Hashtable. Please share some sample C# code for creating generic hashtable classes. I need this for a demo.
编辑:谢谢你的答案
推荐答案
请注意,字典是不是随时可替换哈希表中的100%。
Note that Dictionary is not a 100% drop in replacement for HashTable.
有一个在他们处理空值的方式稍有不同。 如果试图引用不存在一个关键的词典抛出异常。哈希表将只返回null。 其原因是,该值可能是值类型,它的不能的为空。在哈希表中的值总是对象,所以返回null至少是可能的。
There is a slight difference in the way they handle NULLs. The dictionary will throw an exception if you try to reference a key that doesn't exist. The HashTable will just return null. The reason is that the value might be a value type, which cannot be null. In a Hashtable the value was always Object, so returning null was at least possible.
这篇关于什么是一个Hashtable的通用版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!