13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>C#</strong> LANGUAGE SPECIFICATIONThe grammar for a cast-expression leads to certain syntactic ambiguities. [Example: For example, theexpression (x)–y could either be interpreted as a cast-expression (a cast of –y to type x) or as an additiveexpressioncombined with a parenthesized-expression (which computes the value x – y). end example]To resolve cast-expression ambiguities, the following rule exists: A sequence of one or more tokens (§9.4)enclosed in parentheses is considered the start of a cast-expression only if at least one of the following aretrue:• 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 closingparentheses is the token “~”, the token “!”, the token “(”, an identifier (§9.4.1), a literal (§9.4.4), or anykeyword (§9.4.3) except as and is.The term “correct grammar” above means only that the sequence of tokens must conform to the particulargrammatical production. It specifically does not consider the actual meaning of any constituent identifiers.[Example: For example, if x and y are identifiers, then x.y is correct grammar for a type, even if x.ydoesn’t actually denote a type. end example][Note: From the disambiguation rule, it follows that, if x and y are identifiers, (x)y, (x)(y), and (x)(-y)are cast-expressions, but (x)-y is not, even if x identifies a type. However, if x is a keyword that identifiesa predefined type (such as int), then all four forms are cast-expressions (because such a keyword could notpossibly be an expression by itself). end note]14.7 Arithmetic operatorsThe *, /, %, +, and – operators are called the arithmetic operators.multiplicative-expression:unary-expressionmultiplicative-expression * unary-expressionmultiplicative-expression / unary-expressionmultiplicative-expression % unary-expressionadditive-expression:multiplicative-expressionadditive-expression + multiplicative-expressionadditive-expression – multiplicative-expression14.7.1 Multiplication operatorFor an operation of the form x * y, binary operator overload resolution (§14.2.4) is applied to select aspecific operator implementation. The operands are converted to the parameter types of the selectedoperator, and the type of the result is the return type of the operator.The predefined multiplication operators are listed below. The operators all compute the product of x and y.• Integer multiplication:int operator *(int x, int y);uint operator *(uint x, uint y);long operator *(long x, long y);ulong operator *(ulong x, ulong y);In a checked context, if the product is outside the range of the result type, aSystem.OverflowException is thrown. In an unchecked context, overflows are not reported andany significant high-order bits outside the range of the result type are discarded.• Floating-point multiplication:float operator *(float x, float y);double operator *(double x, double y);156

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

Saved successfully!

Ooh no, something went wrong!