Skip to content

Instantly share code, notes, and snippets.

@dresswithpockets
Last active August 1, 2017 01:54
Show Gist options
  • Save dresswithpockets/9cbca68bb61621453cb4f4c5260e0980 to your computer and use it in GitHub Desktop.
Save dresswithpockets/9cbca68bb61621453cb4f4c5260e0980 to your computer and use it in GitHub Desktop.
// 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