Skip to content

Instantly share code, notes, and snippets.

@kmorcinek
Created June 19, 2012 10:23
Show Gist options
  • Save kmorcinek/2953411 to your computer and use it in GitHub Desktop.
Save kmorcinek/2953411 to your computer and use it in GitHub Desktop.
Extension methods for generic Dictionary
using System.Collections.Generic;
namespace KMorcinek.Common
{
public static class DictionaryExtensions
{
public static void IncrementAt<T>(this Dictionary<T, int> dictionary, T index)
{
int count = 0;
dictionary.TryGetValue(index, out count);
dictionary[index] = ++count;
}
}
}
var newDic = oldDic.ToDictionary(x => x.Value, x => x.Key);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment