Answer to the textbook:
Operator overloading is not part of the Common Language Specification, which means that compiler authors can ignore or only partially support it if they want. As a library writer, you are responsible for providing alternative ways for people to work with the class.
The pragmatic answer:
Because this is a stupid thing in the first place. The op_GreaterThan method was explicitly created for comparison. What it is, you should not do โinterestingโ things with it, as if giving in to two terms. The CLR only allows you to abuse it, because it must support legacy languages โโsuch as C ++.
By the way, there is overload specifically for combining two things together. It is called op_Concatenate. You really should use it instead of op_GreaterThan.
EDIT
Almost good answer:
In F #, the concatenation operator I mentioned is ^.
I call this an almost good answer because I'm not sure if C # supports it. I think this is only allowed in VB and F #.
EDIT No. 2
It seems that F # does not honor overload ^.
EDIT No. 3
WTF going on here? F # does not comply with the> operator at all. Of course, you can overload it and it will correctly emit the op_GreaterThan method, but it ignores it. It doesn't even try to use op_GreaterThan, instead, it looks for the System.IComparable interface.
Worse, it is a runtime check. Despite the fact that it can statically determine that the Foo class does not implement IComparable, it still goes and compiles the code anyway.
source share