tags:

views:

479

answers:

3

My understanding is that Dictionary does not have boxing issues and faster in performance. Are there cases that the usage of Hashtable would be more advisable compared to Dictionary? Thanks

+8  A: 

Hashtable is pretty much deprecated. It might be useful for interfacing with legacy code.

Dictionary is a generic class introduced in .NET 2.0, along with other classes in System.Collections.Generic namespace. They supersede classes in System.Collections namespace.

Mehrdad Afshari
+3  A: 

The main advantage of HashTable is that you can use it and target .NET < 2.0.

Otherwise, Dictionary<T,Y> (used correctly) is pretty much better in every way.

Reed Copsey
+7  A: 

For .Net 2.0, you pretty much always want Dictionary. However, be warned that it's not just a "drop in replacement" for an existing Hashtable. There are some differences in the way they work (mostly how they handle nulls) that mean you do need to check your code first.

Joel Coehoorn
+1 For mentioning handling of nulls. It might be good to explain that more as that can be a bit unexpected to get an exception instead of null when a key does not exist in the dictionary.
Andrew Hare