CATEGORII DOCUMENTE 

Issue
We need to write this section.
unaryexpression:
primaryexpression
+ unaryexpression
 unaryexpression
! unaryexpression
~ unaryexpression
* unaryexpression
preincrementexpression
predecrementexpression
castexpression
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 unary plus operators are:
int operator +(int x);
uint operator +(uint x);
long operator +(long x);
ulong operator +(ulong x);
float operator +(float x);
double operator +(double x);
decimal operator +(decimal x);
For each of these operators, the result is simply the value of the operand.
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 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 (−2^{31}) to be written as a decimal integer literal (§2.4.4.2).
If the operand of the negation operator is of type ulong, an error occurs. An exception is the rule that permits the long value −9223372036854775808 (−2^{63}) to be written as decimal integer literal (§2.4.4.2).
Floatingpoint 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
Decimal negation:
decimal operator –(decimal x);
The result is computed by subtracting x from zero.
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. Only one predefined logical negation operator exists:
bool operator !(bool x);
This operator computes the logical negation of the operand: If the operand is true, the result is false. If the operand is false, the result is true.
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).
preincrementexpression:
++ unaryexpression
predecrementexpression:
 unaryexpression
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 compiletime 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 runtime 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.
The ++ and  operators also support postfix notation, as described in §7.5.9. 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.
A castexpression is used to explicitly convert an expression to a given type.
castexpression:
( type ) unaryexpression
A castexpression of the form (T)E, where T is a type and E is a unaryexpression, performs an explicit conversion (§6.2) of the value of E to type T. If no explicit conversion exists from the type of E to T, an error occurs. Otherwise, the result is the value produced by the explicit conversion. The result is always classified as a value, even if E denotes a variable.
The grammar for a castexpression leads to certain syntactic ambiguities. For example, the expression (x)–y could either be interpreted as a castexpression (a cast of –y to type x) or as an additiveexpression combined with a parenthesizedexpression (which computes the value x – y).
To resolve castexpression ambiguities, the following rule exists: A sequence of one or more tokens (§2.4) enclosed in parentheses is considered the start of a castexpression only if at least one of the following are true:
The sequence of tokens is correct grammar for a type, but not for an expression.
The sequence of tokens is correct grammar for a type, and the token immediately following the closing parentheses is the token “~”, the token “!”, the token “(”, an identifier (§2.4.1), a literal (§2.4.4), or any keyword (§2.4.3) except as and is.
The above rules mean that only if the construct is unambiguously a castexpression is it considered a castexpression.
The term “correct grammar” above means only that the sequence of tokens must conform to the particular grammatical production. It specifically does not consider the actual meaning of any constituent identifiers. For example, if x and y are identifiers, then x.y is correct grammar for a type, even if x.y doesn’t actually denote a type.
From the disambiguation rules it follows that, if x and y are identifiers, (x)y, (x)(y), and (x)(y) are castexpressions, but (x)y is not, even if x identifies a type. However, if x is a keyword that identifies a predefined type (such as int), then all four forms are castexpressions (because such a keyword could not possibly be an expression by itself).

Vizualizari: 404
Importanta:
Termeni si conditii de utilizare  Contact
© SCRIGROUP 2019 . All rights reserved
Distribuie URL
Adauga cod HTML in site