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 ExpressionsOtherwise, let R be the run-time type of the instance referenced by e. If R and T are the same type, if R is areference type and an implicit reference conversion from R to T exists, or if R is a value type and T is aninterface type that is implemented by R, the result is the reference given by e with the compile-time type T.Otherwise, the result is the value null with the compile-time type T.• Otherwise, the indicated conversion is never possible, and a compile-time error occurs.The as operator only performs reference conversions and boxing conversions. Other conversions, such asuser defined conversions, are not possible with the as operator and should instead be performed using castexpressions.14.10 Logical operatorsThe &, ^, and | operators are called the logical operators.and-expression:equality-expressionand-expression & equality-expressionexclusive-or-expression:and-expressionexclusive-or-expression ^ and-expressioninclusive-or-expression:exclusive-or-expressioninclusive-or-expression | exclusive-or-expressionFor an operation of the form x op y, where op is one of the logical operators, overload resolution (§14.2.4) isapplied to select a specific operator implementation. The operands are converted to the parameter types ofthe selected operator, and the type of the result is the return type of the operator.The predefined logical operators are described in the following sections.14.10.1 Integer logical operatorsThe predefined integer logical operators are:int operator &(int x, int y);uint operator &(uint x, uint y);long operator &(long x, long y);ulong operator &(ulong x, ulong y);int operator |(int x, int y);uint operator |(uint x, uint y);long operator |(long x, long y);ulong operator |(ulong x, ulong y);int operator ^(int x, int y);uint operator ^(uint x, uint y);long operator ^(long x, long y);ulong operator ^(ulong x, ulong y);The & operator computes the bitwise logical AND of the two operands, the | operator computes the bitwiselogical OR of the two operands, and the ^ operator computes the bitwise logical exclusive OR of the twooperands. No overflows are possible from these operations.14.10.2 Enumeration logical operatorsEvery enumeration type E implicitly provides the following predefined logical operators:E operator &(E x, E y);E operator |(E x, E y);E operator ^(E x, E y);The result of evaluating x op y, where x and y are expressions of an enumeration type E with an underlyingtype U, and op is one of the logical operators, is exactly the same as evaluating (E)((U)x op (U)y). In other169

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

Saved successfully!

Ooh no, something went wrong!