Whidbey Dictionary Exceptions

In Whidbey, the current implementation of the generic Dictionary class will throw an exception when you do something like this:

string s = dict[”myValue”];

If “myValue” is not in the Dictionary. As you probably know, the current Dictionary implementation (ie, Hashtable) returns null in this case, which is a much better solution to the problem. The reasoning behind this decision is that when the dictionary contains value types, you can't return a null value. Understandable, but this is a lame solution to the problem in a lot of situations. IMO, a much better solution would be either:

A) use a generic constraint to ensure that the ValueType implementation throws exceptions, while the reference type implementation does not

B) use nullable types

More info: http://weblogs.asp.net/brada/archive/2004/04/26/120438.aspx

No Comments