@ Jay Mooney : The .NET common class Dictionary is actually a hash table, only with fixed types.
The code you showed should not convince anyone to use a hashtable instead of a dictionary, since both parts of the code can be used for both types.
For a hash table:
foreach(object key in h.keys) { string keyAsString = key.ToString();
For a dictionary:
foreach(string key in d.keys) { string valAsString = d[key].ToString(); System.Diagnostics.Debug.WriteLine(key + " " + valAsString); }
And just the same for the other with KeyValuePair, just use the non-generic version for the Hashtable and the generic version for the dictionary.
So, it is just as simple, but the Hashtable uses Object for both the key and the value, which means that you will enter all types of values and you have no type safety, and the dictionary uses general types and is therefore better.
Lasse Vågsæther Karlsen Aug 12 '08 at 13:25 2008-08-12 13:25
source share