Q:

Dictionary of a class

I have a dictionary
public static Dictionary<SymbolAndStrategy, int> allPositions

SymbolAndStrategy is a class containing 2 different class, Class Symbol and Class Strategy. But when I tried to use it like as this,
allPositions.Add(new SymbolAndStrategy(StrategyName.Apple, this.ProductKey), 0);
allPositions[new SymbolAndStrategy(StrategyName.Apple, this.ProductKey)]++;

the compiler will complain "key not found" even the 2 have the SymbolAndStrategy key. 

A:

The complain of the compailer is probabbly derives from the fact that you didn't override GetHashCode() and Equal() methods of your type in order to make equal 2 different instances by their  content. 
In short 
new SymbolAndStrategy(StrategyName.Apple, this.ProductKey) create a new instance, a new allocation. In order to "explain" to the framework that those 2 instances are equal (the one present in the dictionary as a key, and another you use for a query) you need to override those 2 methods mentioned above accordingly inside SymbolAndStrategy type.  
More on that Implementing the Equals Method 

