Well, not exactly. A generic Dictionary is a nice alternative to Hashtable
because a Hashtable takes System.Object as key and value types. Using a generic
dictionary, I can set the type of key and value (in this case the key is a
string and the value is an integer). Unfortunately, unlike Hashtable which
returns null if an item is not found, a generic Dictionary will throw an
exception. But you can avoid that happening by using TryGetValue(). Pretty
slick!
Dictionary<string,
int> d = new
Dictionary<string,
int>();
d.Add("test1",
1);
d.Add("test2",
2);
int x;
bool b = d.TryGetValue("test2",
out x);
Console.WriteLine("{0},
{1}", b, x);