I\'ve got code like this:
if (CounterForEachRelatedTagDict.Select(x => x.Key).Contains(tag.Key))
CounterForEachRelatedTagDict[tag.Key] += tag.Value;
First:You can use the ContainsKey
method instead of that Linq Query.
Second: You must override the GetHashCode
and Equals
for MyType
. that's the way that Dictionary look up and compare the keys.
Check out these similar questions: Dictionary.ContainsKey return False, but a want True, Using an object as a generic Dictionary key