In the next C # snippet, I override the == method. _type is a short number. Therefore, I actually say that two WorkUnitType match if those two short match.
public static bool operator ==(WorkUnitType type1, WorkUnitType type2) { if (type1 == null || type2 == null) return false; return type1._type == type2._type; }
Because R # is warning me, and itβs very clear why type1 / type2 might be empty. I am trying to catch this with the if above.
Now I get a StackOverflowException , which makes sense because I am actually calling an override.
Question: How to write this method "correctly." How can I catch the case when type1 or type2 can be null ?
My best guess: Maybe I'm just misusing == here, and equality checking should be done with an override of Equals . But still, I think the problem exists. So where is my mistake in reasoning?
c #
Stephan
source share