I'm writing a class library to solve non-linear equations using newton's method. I stumbled across operator-overloading and thought about overloading the ==-Operator. Something like expression1 == expression2
returns the solution as a Constant
, which is basically a wrapper-class of System.Double
:
public static Constant operator ==(Derivable d1, Derivable d2)
{
return d1.Equal(d2);
}
Although it compiles perfectly fine and works, I was asking myself if it would ever be a reasonable design-choice to overload the ==-Operator
to return something else than the equality of two objects as a bool
, especially because you also have to overload the !=-Operator
. Is this bad practice and should I rather just use my method Equal
?