X hits on this document

851 views

0 shares

0 downloads

0 comments

161 / 396

C# LANGUAGE SPECIFICATION

When x is of type int or long, the low-order bits of x are discarded, the remaining bits are shifted right, and the high-order empty bit positions are set to zero if x is non-negative and set to one if x is negative.

When x is of type uint or ulong, the low-order bits of x are discarded, the remaining bits are shifted right, and the high-order empty bit positions are set to zero.

For the predefined operators, the number of bits to shift is computed as follows:

When the type of x is int or uint, the shift count is given by the low-order five bits of count. In other words, the shift count is computed from count & 0x1F.

When the type of x is long or ulong, the shift count is given by the low-order six bits of count. In other words, the shift count is computed from count & 0x3F.

If the resulting shift count is zero, the shift operators simply return the value of x.

Shift operations never cause overflows and produce the same results in checked and unchecked contexts.

When the left operand of the >> operator is of a signed integral type, the operator performs an arithmetic shift right wherein the value of the most significant bit (the sign bit) of the operand is propagated to the high-order empty bit positions. When the left operand of the >> operator is of an unsigned integral type, the operator performs a logical shift right wherein high-order empty bit positions are always set to zero. To perform the opposite operation of that inferred from the operand type, explicit casts can be used. For example, if x is a variable of type int, the operation unchecked((int)((uint)x >> y)) performs a logical shift right of x.

7.9 Relational and type-testing operators

The ==, !=, <, >, <=, >=, is and as operators are called the relational and type-testing operators.

relational-expression: shift-expression relational-expression   <   shift-expression relational-expression   >   shift-expression relational-expression   <=   shift-expression relational-expression   >=   shift-expression relational-expression   is   type relational-expression   as   type

equality-expression: relational-expression equality-expression   ==   relational-expression equality-expression   !=   relational-expression

The is operator is described in §‎7.9.9 and the as operator is described in §‎7.9.10.

The ==, !=, <, >, <= and >= operators are comparison operators. For an operation of the form x op y, where op is a comparison operator, overload resolution (§‎7.2.4) is applied to select a specific operator implementation. The operands are converted to the parameter types of the selected operator, and the type of the result is the return type of the operator.

The predefined comparison operators are described in the following sections. All predefined comparison operators return a result of type bool, as described in the following table.

Operation

Result

x == y

true if x is equal to y, false otherwise

x != y

true if x is not equal to y, false otherwise

148Copyright Microsoft Corporation 1999-2003. All Rights Reserved.

Document info
Document views851
Page views851
Page last viewedMon Dec 05 04:42:08 UTC 2016
Pages396
Paragraphs9401
Words133190

Comments