Answer the question
In order to leave comments, you need to log in
Is the Equals method overridden correctly in C#?
The Microsoft site provides an example of how to override the Equals method.
Confusingly, there is no this.GetType() != other.GetType() check, as is usually given in examples.
Do you think this is correct?
Answer the question
In order to leave comments, you need to log in
In this case, the implementation is correct, but it may behave incorrectly if you create a descendant of ImaginaryNumber.
So in a good way it is necessary to check the types through GetType, which you noticed.
GetHashCode, by the way, is now recommended to be implemented through the HashCode structure
When it is cast from an object there and the type is checked
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question