Overloading Operators
Operator overloading is the capability to redefine C# operators. Overloaded operators apply to the class in which they are defined. Not all operators can be overloaded. Also, there are restrictions placed on when certain operators can be overloaded, such as requiring == and != to be defined together. This section discusses how to overload operators and the rules governing their creation.
For Java ProgrammersJava doesn't have operator overload support, but C# provides comprehensive support. |
Overloaded unary operators require an argument of the same type of class or struct they are defined in. The following unary operators can be overloaded:
+ | ++ |
- | -- |
! | true |
~ | False |
Note
The prefix and postfix (++) and (--) operators can't be overloaded ...
Get C# Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.