a575963da9
Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
14 lines
3.6 KiB
XML
14 lines
3.6 KiB
XML
<?xml version="1.0"?>
|
|
<clause number="14.5.9" title="Postfix increment and decrement operators">
|
|
<paragraph>
|
|
<grammar_production><name><non_terminal where="14.5.9">post-increment-expression</non_terminal></name> : <rhs><non_terminal where="14.5">primary-expression</non_terminal><terminal>++</terminal></rhs></grammar_production>
|
|
<grammar_production><name><non_terminal where="14.5.9">post-decrement-expression</non_terminal></name> : <rhs><non_terminal where="14.5">primary-expression</non_terminal><terminal>--</terminal></rhs></grammar_production>
|
|
</paragraph>
|
|
<paragraph>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. </paragraph>
|
|
<paragraph>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. </paragraph>
|
|
<paragraph>Unary operator overload resolution (<hyperlink>14.2.3</hyperlink>) is applied to select a specific operator implementation. Predefined ++ and --operators exist for the following types: <keyword>sbyte</keyword>, <keyword>byte</keyword>, <keyword>short</keyword>, <keyword>ushort</keyword>, <keyword>int</keyword>, <keyword>uint</keyword>, <keyword>long</keyword>, <keyword>ulong</keyword>, <keyword>char</keyword>, <keyword>float</keyword>, <keyword>double</keyword>, <keyword>decimal</keyword>, 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. </paragraph>
|
|
<paragraph>The run-time processing of a postfix increment or decrement operation of the form x++ or x--consists of the following steps: <list><list_item> If x is classified as a variable: </list_item><list><list_item> x is evaluated to produce the variable. </list_item><list_item> The value of x is saved. </list_item><list_item> The selected operator is invoked with the saved value of x as its argument. </list_item><list_item> The value returned by the operator is stored in the location given by the evaluation of x. </list_item><list_item> The saved value of x becomes the result of the operation. </list_item></list><list_item> If x is classified as a property or indexer access: </list_item><list><list_item> 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. </list_item><list_item> The get accessor of x is invoked and the returned value is saved. </list_item><list_item> The selected operator is invoked with the saved value of x as its argument. </list_item><list_item> The set accessor of x is invoked with the value returned by the operator as its value argument. </list_item><list_item> The saved value of x becomes the result of the operation. </list_item></list></list></paragraph>
|
|
<paragraph>The ++ and --operators also support prefix notation (<hyperlink>14.6.5</hyperlink>). 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. </paragraph>
|
|
<paragraph>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. </paragraph>
|
|
</clause>
|