14.6.2 Unary minus operator

For an operation of the form ?x, unary operator overload resolution (?4.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:
?Integer negation:
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
-2147483648 (-231) to be written as a
decimal integer literal (?.4.4.2).
If the operand of the negation operator is of type ulong, a compile-time
error occurs. An exception is
the rule that permits the long value -9223372036854775808 (-263) to be
written as a decimal integer
literal (?.4.4.2).
?Floating-point negation:
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 negation:
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.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值