Are Hashtable Objects Still Helpful?

Has the System.Collections.Hashtable object changed?

With the implementation and refinement of generics from C # v2 and v3, this has been a long time since I found a Hashtable more suitable than a generic dictionary. Literally, I can't remember the last time I used a hashtable.

It's just interesting if anyone found another case where a Hashtable is still suitable or preferred for implementation and the basis for this solution is ease of use, performance, collection size, object type, etc.

UPDATE: meant limiting this question to C #.

+4
source share
2 answers

Besides the obvious case, when you have to use a Hashtable in an existing API that expects one (for example, languages ​​that do not yet support generic types). You may also need to use them if you need to access them from COM. I believe that a Hashtable is COM visible while a Dictionary is not.

Other than that, you usually want to use Dictionary <> because it avoids boxing (a performance hit) and provides type safety.

+12
source

Hashtable is still useful when you are dealing with a language or version of a language that does not support generic types.

EDIT

For C # 2.0 or higher, Hashtable really only useful for the following scenarios.

  • You want the previous semantics of an IDictionary instance that returns null or throw if the key is not in the table.
  • Working with an obsolete API that exposes a Hashtable value

Hashstable is still useful as a general purpose map if you are stuck with C # 1.0 :)

+1
source

All Articles