Created
October 22, 2014 08:27
-
-
Save Larry57/ead37745117702d6a781 to your computer and use it in GitHub Desktop.
Process an element in a Dictionary only if it exists
This file contains 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
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