Click here to Skip to main content
15,885,839 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to know what is exactly diff. hashtable and dictionary with example.
thanks in advance.
Posted

Very roughly: the class System.Collections.Hashtable is obsolete version with functionality very similar to the generic class System.Collections.Generic.Dictionary created before generic were implemented in v.2.0 of the .NET Framework.

This class was not formally marked by the obsolete attribute, because there is nothing wrong with it; and it can be used in legacy code, but using it in new code is totally pointless. Generics are way better, because you don't need to use error-prone typecasts. Instead, choose from these three classes System.Collections.Generic.Dictionary, System.Collections.Generic.SortedDictionary or System.Collections.Generic.SortedList, http://msdn.microsoft.com/en-us/library/0sbxh9x2.aspx[^].

They are different in implementations, but, from the standpoint of the using code, they are different mainly in the different trade-off between performance and redundancy.

—SA
 
Share this answer
 
v2
Comments
Espen Harlinn 19-Nov-12 19:19pm    
5'ed!
Sergey Alexandrovich Kryukov 19-Nov-12 19:29pm    
Thank you, Espen.
--SA
Below link provides you all the differences you want, however, i would try to find answers my self before posting:

http://msdn.microsoft.com/en-us/library/4yh14awz.aspx[^]
 
Share this answer
 
A Dictionary is a generic version of a Hashtable.
In a Hashtable, you can only add objects as a key and a value.
In a Dictionary, you can choose the type for the key and for the value:
C#
Hashtable hashtable1 = new Hashtable();
           hashtable1.Add(1, "HashtableValue1"); // add a key/value pair to the Hashtable
           Dictionary<int,> dictionary1 = new Dictionary<int,>();
           dictionary1.Add(1, "DictionaryValue1"); // add a key/value pair to the Dictionary
           string hashtableValue1 = (string)hashtable1[1]; // get the value of the Hashtable and cast it to a string
           string dictionaryValue1 = dictionary1[1]; // get the value of the Dictionary, you don't need to cast the value to a string

Hope this helps.
 
Share this answer
 
Kindly refer following link

http://stackoverflow.com/questions/876656/difference-between-dictionary-and-hashtable[^]

[edit]clickable link[/edit]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900