13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>C#</strong> LANGUAGE SPECIFICATIONUnary operator overload resolution (§14.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 thevalue produced by adding 1 to the operand, and the predefined -- operators return the value produced bysubtracting 1 from the operand.The run-time processing of a postfix increment or decrement operation of the form x++ or x-- consists ofthe 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 withx 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 (§14.6.5). The result of x++ or x-- is the value of xbefore the operation, whereas the result of ++x or --x is the value of x after the operation. In either case, xitself 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.14.5.10 The new operatorThe new operator is used to create new instances of types.There are three forms of new expressions:• Object creation expressions are used to create new instances of class types and value types.• Array creation expressions are used to create new instances of array types.• Delegate creation expressions are used to create new instances of delegate types.The new operator implies creation of an instance of a type, but does not necessarily imply dynamicallocation of memory. In particular, instances of value types require no additional memory beyond thevariables in which they reside, and no dynamic allocations occur when new is used to create instances ofvalue types.14.5.10.1 Object creation expressionsAn object-creation-expression is used to create a new instance of a class-type or a value-type.object-creation-expression:new type ( argument-list opt )The type of an object-creation-expression must be a class-type or a value-type. The type cannot be anabstract class-type.146

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!