Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
C-sharp language specification.2004.pdf
Скачиваний:
14
Добавлен:
23.08.2013
Размер:
2.55 Mб
Скачать

Chapter 14 Expressions

1using System;

2delegate void D(int x);

3class Test

4{

5

public static void M1(int i) { /* … */ }

6public static void M2(int i) { /* … */ }

7}

8class Demo

9{

10

static void Main() {

 

11

D cd1 = new D(Test.M1);

 

12

D cd2 = new D(Test.M2);

 

13

D cd3 = cd1 + cd2 + cd2 + cd1;

// M1 + M2 + M2 + M1

14

cd3 -= cd1;

// => M1 + M2 + M2

15

cd3 = cd1 + cd2 + cd2 + cd1;

// M1 + M2 + M2 + M1

16

cd3 -= cd1 + cd2;

// => M2 + M1

17

cd3 = cd1 + cd2 + cd2 + cd1;

// M1 + M2 + M2 + M1

18

cd3 -= cd2 + cd2;

// => M1 + M1

19

cd3 = cd1 + cd2 + cd2 + cd1;

// M1 + M2 + M2 + M1

20

cd3 -= cd2 + cd1;

// => M1 + M2

21

cd3 = cd1 + cd2 + cd2 + cd1;

// M1 + M2 + M2 + M1

22

cd3 -= cd1 + cd1;

// => M1 + M2 + M2 + M1

23}

24}

25end example]

2614.8 Shift operators

27The << and >> operators are used to perform bit shifting operations.

28shift-expression:

29

additive-expression

30

shift-expression

<< additive-expression

31

shift-expression

right-shift additive-expression

32 For an operation of the form x << count or x >> count, binary operator overload resolution (§14.2.4) is

33applied to select a specific operator implementation. The operands are converted to the parameter types of

34the selected operator, and the type of the result is the return type of the operator.

35When declaring an overloaded shift operator, the type of the first operand shall always be the class or struct

36containing the operator declaration, and the type of the second operand shall always be int.

37The predefined shift operators are listed below.

38Shift left:

39int operator <<(int x, int count);

40uint operator <<(uint x, int count);

41long operator <<(long x, int count);

42ulong operator <<(ulong x, int count);

43The << operator shifts x left by a number of bits computed as described below.

44The high-order bits outside the range of the result type of x are discarded, the remaining bits are shifted

45left, and the low-order empty bit positions are set to zero.

46Shift right:

47int operator >>(int x, int count);

48uint operator >>(uint x, int count);

49long operator >>(long x, int count);

50ulong operator >>(ulong x, int count);

51The >> operator shifts x right by a number of bits computed as described below.

197

Соседние файлы в предмете Электротехника