Does your extension method compile correctly? When I try to compile it I get: "Type parameter declaration must be an identifier not a type".
The reason is that in this line:
public static int SetOrIncrement<TKey, int>(this Dictionary<TKey, int> dict, TKey key, int set) {
the int
in the generic parameters for the method is not valid. Instead this should work:
public static int SetOrIncrement<TKey>(this Dictionary<TKey, int> dict, TKey key, int set) {
The reason being that TKey
is the only type that varies. The int is always the same so isn't a generic parameter.