sandrock / SrkToolkit

Here goes another set of libraries to help out. Separated into a few assemblies to avoid loading too much stuff in your app.
Apache License 2.0
2 stars 3 forks source link

Create extension IDictionary<K, V>.GetByKey() that returns null when the key does not exist #4

Closed sandrock closed 7 years ago

sandrock commented 8 years ago

The Dictionary class throws an exception when you index-access an item that does not exist.

var dictionary = new Dictionary<string, string>();
var value = dictionary["Hello"]; // throws KeyNotFoundException: The given key was not present in the dictionary

We would like a method that would return null instead of throwing an exception.