What is the generic version of a Hashtable?

后端 未结 5 1770
广开言路
广开言路 2020-12-14 05:26

I have been learning the basics of generics in .NET. However, I don\'t see the generic equivalent of Hashtable. Please share some sample C# code for creating

5条回答
  •  时光取名叫无心
    2020-12-14 06:05

    Dictionary

    Note that Dictionary is not a 100% drop in replacement for HashTable.

    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.

提交回复
热议问题