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.

Chapter 8 <strong>Language</strong> Overview}static void Main() {byte[] arr = new byte[] {1, 2, 3, 4, 5};WriteLocations(arr);}shows an unsafe block in a method named WriteLocations that fixes an array instance and uses pointermanipulation to iterate over the elements. The index, value, and location of each array element are written tothe console. One possible example of output is:arr[0] at 0x8E0360 is 1arr[1] at 0x8E0361 is 2arr[2] at 0x8E0362 is 3arr[3] at 0x8E0363 is 4arr[4] at 0x8E0364 is 5but, of course, the exact memory locations may be different in different executions of the application.8.5 Expressions<strong>C#</strong> includes unary operators, binary operators, and one ternary operator. The following table summarizes theoperators, listing them in order of precedence from highest to lowest:Section 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 expression contains multiple operators, the precedence of the operators controls the order in whichthe individual operators are evaluated. For example, the expression x + y * z is evaluated asx + (y * z) because the * operator has higher precedence than the + operator.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. For example, x + y + z is evaluated as (x + y) + z.• The assignment operators and the conditional operator (?:) are right-associative, meaning thatoperations are performed from right to left. For example, x = y = z is evaluated as x = (y = z).27

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

Saved successfully!

Ooh no, something went wrong!