Skip to content

Instantly share code, notes, and snippets.

@Larry57
Created October 22, 2014 08:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Larry57/ead37745117702d6a781 to your computer and use it in GitHub Desktop.
Save Larry57/ead37745117702d6a781 to your computer and use it in GitHub Desktop.
Process an element in a Dictionary only if it exists
namespace System.Collections.Generic
{
public static class DictionaryExtension
{
public static void ProcessValue<TKey, TValue>(this IDictionary<TKey, TValue> x, TKey key, Action<TValue> action)
{
TValue o;
if (x.TryGetValue(key, out o))
action(o);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment