Skip to content

Instantly share code, notes, and snippets.

@khigia
Created October 16, 2009 02:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save khigia/211479 to your computer and use it in GitHub Desktop.
Save khigia/211479 to your computer and use it in GitHub Desktop.
C# dictionary lookup with default
public static V GetValueOrDefault<K, V>(this Dictionary<K, V> dic, K key, V defaultVal)
{
V ret;
return dic.TryGetValue (key, out ret) ? ret : defaultVal;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment