why c# not allowed operator overloading while C++ do?
I got this error, when trying to overload.
Overloadable binary operator expected
Operator overloading, C# allows. (Yoda version)
You can overload operators in C#:
Before you decide to use operator overloading, please read at the very least, the following:
EDIT in response to op's edit:
The +=
is a non-overloadable operator. However, it resolves to +
, and +
is overloadable. Have a look here for which operators you can and can not overload.
Operators that can be overloaded:
+
, -
, !
, ~
, ++
, --
, true
, false
+
, -
, *
, /
, %
, &
, |
, ^
, <<
, >>
==
, !=
, <
, >
, <=
, >=
(The comparison operators can be overloaded but see note in link)
It does allow operator overloading..
that said, it's generally recommended not to override operators since it changes the semantics of your code and therefore makes it less maintainable by others.
c# does allow operator overloading. MSDN tutorial here.
You can overload operators in C#. Operator Overloading Tutorial