I don't know if this is the way to go
I have Dictionary<Class, int>
the int value - counts how many of that Class is stored there
I have a method that does that
so if we did thisCode:public void DictionaryAddClass(Class Class) { if (Dictionary.ContainsKey(Class)) { int value = Dictionary[Class]; value++; Dictionary[Class] = value; } else { Dictionary.Add(Class, 1); } }
the value of that Key would be 3Code:Class myclass = new Class ("AClass"); DictionaryAddClass(myclass ); DictionaryAddClass(myclass ); DictionaryAddClass(myclass );
Here is the probliem - I learned that if somewhere else I create a new class
Class myclass = new Class ("AClass");
even with the same parameters it treats it as a new Key
and this > if (Dictionary.ContainsKey(Class))
will not be true
I need to hold a number of these Classes in some kind of Inventory and store how many I have. Should I be using Dictionary or doing something else?




Reply With Quote