In C# I can override ==
with my own implementation. For example:
public static bool operator ==(SomeType x, SomeOtherType y)
{
return false;
}
Does the order of parameters matter here? Does it make a difference to swap SomeType
with SomeOtherType
?
Yes it does. In your case,
SomeType x;
SomeOtherType y;
bool b = x == y;
would call your function, but
bool b = y == x;
would not.
Overloaded operator functions in this respect have the same behaviour as any regular function with more than one parameter type: the passed parameters must match the expected types with the order clearly mattering too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With