X hits on this document

774 views

0 shares

0 downloads

0 comments

152 / 396

Chapter ‎18   Unsafe code

For an operation of the form ~x, unary operator overload resolution (§‎7.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 bitwise complement operators are:

int operator ~(int x); uint operator ~(uint x); long operator ~(long x); ulong operator ~(ulong x);

For each of these operators, the result of the operation is the bitwise complement of x.

Every enumeration type E implicitly provides the following bitwise complement operator:

E operator ~(E x);

The result of evaluating ~x, where x is an expression of an enumeration type E with an underlying type U, is exactly the same as evaluating (E)(~(U)x).

7.6.5 Prefix increment and decrement operators

pre-increment-expression: ++   unary-expression

pre-decrement-expression: --   unary-expression

The operand of a prefix 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 prefix 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.

Unary operator overload resolution (§‎7.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 prefix 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 selected operator is invoked with the value of x as its argument.

The value returned by the operator is stored in the location given by the evaluation of x.

The value returned by the operator 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.

The selected operator is invoked with the value returned by the get accessor as its argument.

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

The value returned by the operator becomes the result of the operation.

Copyright Microsoft Corporation 1999-2003. All Rights Reserved.139

Document info
Document views774
Page views774
Page last viewedSat Dec 03 07:32:56 UTC 2016
Pages396
Paragraphs9401
Words133190

Comments