Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
i want to know what is exactly diff. hashtable and dictionary with example.
thanks in advance.
Posted 17-Nov-12 2:00am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
v2
Comments
Espen Harlinn at 19-Nov-12 19:19pm
   
5'ed!
Sergey Alexandrovich Kryukov at 19-Nov-12 19:29pm
   
Thank you, Espen.
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Kindly refer following link
 
http://stackoverflow.com/questions/876656/difference-between-dictionary-and-hashtable[^]
 
[edit]clickable link[/edit]
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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:
 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.
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 543
1 OriginalGriff 384
2 George Jonsson 258
3 Abdul Samad KP 135
4 Animesh Datta 130
0 OriginalGriff 6,099
1 Sergey Alexandrovich Kryukov 5,411
2 CPallini 4,770
3 George Jonsson 3,400
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 18 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100