Skip to content

Instantly share code, notes, and snippets.

@khigia
Created October 16, 2009 02:11
Show Gist options
  • 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