Generic dictionary indexer behaves differently

Today I discovered, the hard way, that if you ask for a key value that doesn’t exist in a generic dictionary you get an exception, whereas for specialised dictionaries (or your own derived ones) you get null. This was especially annoying has I have a load of code expecting null and a colleague changed the dictionary to a generic one. So I had to change the indexer to do a quick "contains key" to return null if the key doesn’t exist.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s