C# I’m trying to compare two different objects (I’m only comparing identical subfields). But I have another place where there’s a check against null. Now I have a problem, it falls through to comparing the two different objects, and that blows up because it’s not expecting null. I tried to put a new method to compare against object, but it doesn’t want to choose that one.
Is it standard practice when overloading operators == or != to check either for null first? Or is there some way to shortcut a comparison to null?
It is standard practice to check for null in equality operators. Take
Stringfor example: