In C #, the operator overload must be declared as public and static, and the overload = and! =, It is best to reload the equals () and gethashcode () methods, because the = and equals () methods should maintain the same logic (not reload the last two methods, will generate a compiler warning)
ClassOther |
Operation Computing Character |
LimitedSystem |
Arithmetic binary Operators |
+ ,*,/,-, % |
None |
Arithmetic unary operator |
+,-, ++,-- |
None |
Bitwise binary operator |
&, |, ^, <,> |
None |
Bitwise unary Operators |
!, ~, True, false |
TrueAndFalseThe operators must be reloaded in pairs. |
Comparison Operators |
= ,! =, >=, <, <=,> |
Must be reloaded in pairs |
Value assignment operator |
+ =,-=, * =,/=, >>=, <=, % = , & =, | =, ^ = |
You cannot explicitly reload these operators.+,-, %They are implicitly overwritten. |
Index Operators |
[] |
You cannot directly reload the index operator. The2The member types of the indexer introduced in chapter allow the support of index operators in the class and Structure |
Data type conversion Operator |
() |
You cannot directly overload the data type conversion operator. User-Defined data type conversion(In this chapter2Introduction)Allow custom data type conversion |