14.6.2 Unary minus operator

王朝other·作者佚名  2006-03-10
窄屏简体版  字體: |||超大  

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.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航