Since your list is List<IItem> , I assume you have something like:
var item1 = Items[0];
or whatever; here item1 variable is introduced as IItem . Operator resolution occurs at build time through static analysis (not at run time through polymorphism / RTTI), so the only available == is the default value for any object , that is, reference equality.
To support your custom operator, you must enter the characters , eg:
Consumable item1 = ..., item2 = ...;
Your roll reaches a similar thing.
Another option is to make sure that == and Equals (and GetHashCode() ) are consistent, and use:
if(Equals(item1, item2)) {...}
which will do a null check and then use your overridden Equals method. This then supports polymorphism, so it doesn't matter what the types are.
source share