ECMA-334 C# Language Specification14.7.5: Subtraction operator |
For an operation of the form x -y, binary operator overload resolution (14.2.4) is applied to select a specific operator implementation. The operands are converted to the parameter types of the selected operator, and the type of the result is the return type of the operator.
The predefined subtraction operators are listed below. The operators all subtract y from x.
int operator -(int x, int y); uint operator -(uint x, uint y); long operator -(long x, long y); ulong operator -(ulong x, ulong y); |
float operator -(float x, float y); double operator -(double x, double y); |
decimal operator {UNICODE_150}(decimal x, decimal y); |
U operator -(E x, E y); |
E operator -(E x, U y); |
D operator -(D x, D y); |
using System; delegate void D(int x); class Test { public static void M1(int i) { /* ... */ } public static void M2(int i) { /* ... */ } } class Demo { static void Main() { D cd1 = new D(Test.M1); D cd2 = new D(Test.M2); D cd3 = cd1 + cd2 + cd2 + cd1; // M1 + M2 + M2 + M1 cd3 -= cd1; // => M1 + M2 + M2 cd3 = cd1 + cd2 + cd2 + cd1; // M1 + M2 + M2 + M1 cd3 -= cd1 + cd2; // => M2 + M1 cd3 = cd1 + cd2 + cd2 + cd1; // M1 + M2 + M2 + M1 cd3 -= cd2 + cd2; // => M1 + M1 cd3 = cd1 + cd2 + cd2 + cd1; // M1 + M2 + M2 + M1 cd3 -= cd2 + cd1; // => M1 + M2 cd3 = cd1 + cd2 + cd2 + cd1; // M1 + M2 + M2 + M1 cd3 -= cd1 + cd1; // => M1 + M2 + M2 + M1 } } |