Is it possible to override the behaviour of a dictionary if an object is not
found?
string ss=null;
Dictionary<string, string> dict = new Dictionary<string,
string>();
// method 1
try { ss = dict["x"]; }
catch (KeyNotFoundException) {/* Ignore */}
// method 2
if (dict.ContainsKey("x")) ss = dict["x"];
In Method 1, if the key is not there then we have the considerable overhead
of an Exception.
In Method 2 it looks as though we need two dictionary scans.
So is it possible to change the default behaviour of a dictionary so it
returns a null value if not found rather than throwing the exception?
--
Paul