14.5.9 Postfix in- & decrement operators

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

post-increment-expression:

primary-expression ++

post-decrement-expression:

primary-expression --

The operand of a postfix increment or decrement operation must be an

expression classified as a variable, a

property access, or an indexer access. The result of the operation is a

value of the same type as the operand.

If the operand of a postfix increment or decrement operation is a property

or indexer access, the property or

indexer must have both a get and a set accessor. If this is not the case, a

compile-time error occurs.

C# LANGUAGE SPECIFICATION

146

Unary operator overload resolution (?4.2.3) is applied to select a

specific operator implementation.

Predefined ++ and -- operators exist for the following types: sbyte, byte,

short, ushort, int, uint,

long, ulong, char, float, double, decimal, and any enum type. The

predefined ++ operators return the

value produced by adding 1 to the operand, and the predefined -- operators

return the value produced by

subtracting 1 from the operand.

The run-time processing of a postfix increment or decrement operation of

the form x++ or x-- consists of

the following steps:

?If x is classified as a variable:

x is evaluated to produce the variable.

The value of x is saved.

The selected operator is invoked with the saved value of x as its argument.

The value returned by the operator is stored in the location given by the

evaluation of x.

The saved value of x becomes the result of the operation.

?If x is classified as a property or indexer access:

The instance expression (if x is not static) and the argument list (if x is

an indexer access) associated with

x are evaluated, and the results are used in the subsequent get and set

accessor invocations.

The get accessor of x is invoked and the returned value is saved.

The selected operator is invoked with the saved value of x as its argument.

The set accessor of x is invoked with the value returned by the operator as

its value argument.

The saved value of x becomes the result of the operation.

The ++ and -- operators also support prefix notation (?4.6.5). The result

of x++ or x-- is the value of x

before the operation, whereas the result of ++x or --x is the value of x

after the operation. In either case, x

itself has the same value after the operation.

An operator ++ or operator -- implementation can be invoked using either

postfix or prefix notation.

It is not possible to have separate operator implementations for the two

notations.

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