Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hashtable vs Dictionary

Tags:

c#

.net

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

like image 813
kaivalya Avatar asked Apr 02 '09 00:04

kaivalya


2 Answers

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.

like image 161
Joel Coehoorn Avatar answered Oct 04 '22 03:10

Joel Coehoorn


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.

like image 45
mmx Avatar answered Oct 04 '22 04:10

mmx