考虑为每个重载操作符的方法都提供相应的友好名称。
你必须遵循这个指导方针来适应 CLS。下表中包含了操作符号以及与它们相对应的可选方法和操作符名称的列表。
C# 操作符号 | 可选方法的名称 | 操作符的名称 |
---|---|---|
未被定义 | ToXxx 或 FromXxx | op_Implicit |
未被定义 | ToXxx 或 FromXxx | op_Explicit |
+(二进制) | Add | op_Addition |
-(二进制) | Subtract | op_Subtraction |
*(二进制) | Multiply | op_Multiply |
/ | Divide | op_Division |
% | Mod | op_Modulus |
^ | Xor | op_ExclusiveOr |
&(二进制) | BitwiseAnd | op_BitwiseAnd |
| | BitwiseOr | op_BitwiseOr |
&& | And | op_LogicalAnd |
|| | Or | op_LogicalOr |
= | Assign | op_Assign |
<< | LeftShift | op_LeftShift |
>> | RightShift | op_RightShift |
未被定义 | LeftShift | op_SignedRightShift |
未被定义 | RightShift | op_UnsignedRightShift |
== | Equals | op_Equality |
> | CompareTo | op_GreaterThan |
< | CompareTo | op_LessThan |
!= | Equals | op_Inequality |
>= | CompareTo | op_GreaterThanOrEqual |
<= | CompareTo | op_LessThanOrEqual |
*= | Multiply | op_MultiplicationAssignment |
-= | Subtract | op_SubtractionAssignment |
^= | Xor | op_ExclusiveOrAssignment |
<<= | LeftShift | op_LeftShiftAssignment |
%= | Mod | op_ModulusAssignment |
+= | Add | op_AdditionAssignment |
&= | BitwiseAnd | op_BitwiseAndAssignment |
|= | BitwiseOr | op_BitwiseOrAssignment |
, | Comma | op_Comma |
/= | Divide | op_DivisionAssignment |
-- | Decrement | op_Decrement |
++ | Increment | op_Increment |
-(一元) | Negate | op_UnaryNegation |
+(一元) | Plus | op_UnaryPlus |
~ | OnesComplement | op_OnesComplement |