J
Jonathan Wood
I'm trying to implement code that uses Dictionary<string, string>.
I got the basics working very quickly, although it took me about an hour to
figure out how to make the comparision case-insensitive.
Now, I'm having trouble because this collection raises an exception rather
than returning null if the specified key is not in the dictionary. I can
use ContainsKey but then I'd have to do another lookup if ContainsKey
returns true. Otherwise, I have to implement another exception handler.
Neither options seems like the most efficient approach to such a simple
task.
Is there any method to get a Dictionary<string, string> value that only
requires a single lookup but intelligently handles keys that are not in the
collection? My preference would be something like this:
var x = dict["key"];
if (x != null)
...
Thanks.
I got the basics working very quickly, although it took me about an hour to
figure out how to make the comparision case-insensitive.
Now, I'm having trouble because this collection raises an exception rather
than returning null if the specified key is not in the dictionary. I can
use ContainsKey but then I'd have to do another lookup if ContainsKey
returns true. Otherwise, I have to implement another exception handler.
Neither options seems like the most efficient approach to such a simple
task.
Is there any method to get a Dictionary<string, string> value that only
requires a single lookup but intelligently handles keys that are not in the
collection? My preference would be something like this:
var x = dict["key"];
if (x != null)
...
Thanks.