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.

Chapter 14 ExpressionsSection Category Operators14.5 Primary x.y f(x) a[x] x++ x-- newtypeof checked unchecked14.6 Unary + - ! ~ ++x --x (T)x14.7 Multiplicative * / %14.7 Additive + -14.8 Shift >14.9 Relational andtype-testing14.9 Equality == !=14.10 Logical AND &14.10 Logical XOR ^14.10 Logical OR |14.11 Conditional AND &&14.11 Conditional OR ||14.12 Conditional ?:< > = is as14.13 Assignment = *= /= %= += -= = &= ^= |=When an operand occurs between two operators with the same precedence, the associativity of the operatorscontrols the order in which the operations are performed:• Except for the assignment operators, all binary operators are left-associative, meaning that operationsare performed from left to right. [Example: For example, x + y + z is evaluated as (x + y) + z.end example]• The assignment operators and the conditional operator (?:) are right-associative, meaning thatoperations are performed from right to left. [Example: For example, x = y = z is evaluated asx = (y = z). end example]Precedence and associativity can be controlled using parentheses. [Example: For example, x + y * z firstmultiplies y by z and then adds the result to x, but (x + y) * z first adds x and y and then multiplies theresult by z. end example]14.2.2 Operator overloadingAll unary and binary operators have predefined implementations that are automatically available in anyexpression. In addition to the predefined implementations, user-defined implementations can be introducedby including operator declarations in classes and structs (§17.9). User-defined operator implementationsalways take precedence over predefined operator implementations: Only when no applicable user-definedoperator implementations exist will the predefined operator implementations be considered, as described in§14.2.3 and §14.2.4.The overloadable unary operators are:+ - ! ~ ++ -- true false[Note: Although true and false are not used explicitly in expressions (and therefore are not included inthe precedence table in §14.2.1), they are considered operators because they are invoked in severalexpression contexts: boolean expressions (§14.16) and expressions involving the conditional (§14.12), andconditional logical operators (§14.11). end note]125

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

Saved successfully!

Ooh no, something went wrong!