Created
July 6, 2010 01:35
-
-
Save jfromaniello/464895 to your computer and use it in GitHub Desktop.
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
public static class DictionaryExtensions | |
{ | |
public static TValue GetOrAdd<TKey, TValue>( | |
this IDictionary<TKey, TValue> dictionary, TKey key, Func<TValue> create) | |
{ | |
TValue result; | |
if(!dictionary.TryGetValue(key, out result)) | |
{ | |
result = create(); | |
dictionary[key] = result; | |
} | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment