private readonly double real;
private readonly double imaginary;
}
public sealed class EntryPoint
{
static void Main()
{
ComplexNumber num1 = new ComplexNumber( 1, 2 );
ComplexNumber num2 = new ComplexNumber( 1, 2 );
bool result = num1.Equals( num2 );
}
}
Now, the comparison inside Main is much more efficient, since the value doesn’t need to be
boxed. The compiler chooses the closest match of the two overloads, which, of course, is the
strongly typed overload of Equals that accepts a ComplexNumber rather than a generic object type.
Internally, the Object.Equals override delegates to the type-safe version of Equals after it checks the
type of the object and unboxes it. It’s important to note that the Object.Equals override first checks
the type to see if it ...