ECMA-334 C# Language Specification14.6.2: Unary minus operator |
For an operation of the form -x, unary operator overload resolution (14.2.3) is applied to select a specific operator implementation. The operand is converted to the parameter type of the selected operator, and the type of the result is the return type of the operator. The predefined negation operators are:
int operator -(int x); long operator -(long x); |
The result is computed by subtracting x from zero. In a checked context, if the value of x is the maximum negative int or long , a System.OverflowException is thrown. In an unchecked context, if the value of x is the maximum negative int or long , the result is that same value and the overflow is not reported. If the operand of the negation operator is of type uint , it is converted to type long , and the type of the result is long . An exception is the rule that permits the int value
float operator -(float x); double operator -(double x); |
The result is the value of x with its sign inverted. If x is NaN, the result is also NaN.
decimal operator -(decimal x); |
The result is computed by subtracting x from zero. Decimal negation is equivalent to using the unary minus operator of type System.Decimal.