Deprecated: Function set_magic_quotes_runtime() is deprecated in /nfs/c01/h05/mnt/2939/domains/ on line 14
Cidamon: Blog: Dictionary, Hashtable and HashSet
Dictionary, Hashtable and HashSet
07 November, 2010

First of all HasSet is different then Dictionary and Hashtable cause it does not allow duplicate value and elements inside a HashSet cannot be accessed through indices, only through an enumerator (which is an iterator).

Now the difference between Dictionary and Hashtable is though Hashtable takes in a key/value pair, but it does so as generic objects as opposed to typed data in Dictionary. And another difference between Dictionary and Hashtable is, Hastable does not preserve the order in which items are added. On the other hand, the Dictionary data structure does keep items in the same order. Because of this behavior Hashtable is faster then Dictionary.

So, ultimately if we require a unique list without key/value pair we should use HashSet (it has been introduced from Framework 3.5). But if we need key/value pair and does not require to preserver the order items are being added we should use Hashtable. We should use Dictionary when we need to use key/value pair and also need to preserver the order items are being added into the list.


Commenting is closed for this article.