How can I change the way a dictionary works, so that if there is no KVP with given key, it returns a default value, without wrapping usual dic["nonexistentKey"] with try-catch?
How can I change the way a dictionary works, so that if there is
Share
You could make your own class which encapsulates a
Dictionary<TKey,TValue>, and implementsIDictionary<TKey,TValue>.This will behave like a dictionary, but you can write the behavior to handle your non-existent key any way you wish.
However, you can’t change the way the actual
Dictionary<TKey,TValue>class functions.