Last active
August 1, 2017 01:54
-
-
Save dresswithpockets/9cbca68bb61621453cb4f4c5260e0980 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The solution I've been using up until now | |
if (Items.ContainsKey(Key)) { | |
var item = Items[Key]; | |
} | |
// Using a single function call to get the value | |
if (Items.TryGetValue(Key, out var item)) { | |
// do something with item | |
} | |
// Using exceptions for error handling | |
try { | |
var item = Items[Key]; | |
} | |
catch (KeyNotFoundException knfe) { | |
} | |
finally { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment