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

Chapter 17 Classes

1is equivalent to

2class A

3{

4

public

const

double

X

=

1.0;

5

public

const

double

Y

=

2.0;

6public const double Z = 3.0;

7}

8end example]

9Constants are permitted to depend on other constants within the same program as long as the dependencies

10are not of a circular nature. The compiler automatically arranges to evaluate the constant declarations in the

11appropriate order. [Example: In the following code

12class A

13{

14

public const int X = B.Z + 1;

15public const int Y = 10;

16}

17class B

18{

19public const int Z = A.Y + 1;

20}

21the compiler first evaluates A.Y, then evaluates B.Z, and finally evaluates A.X, producing the values 10, 11,

22and 12. end example] Constant declarations can depend on constants from other programs, but such

23dependencies are only possible in one direction. [Example: Referring to the example above, if A and B were

24declared in separate programs, it would be possible for A.X to depend on B.Z, but B.Z could then not

25simultaneously depend on A.Y. end example]

2617.4 Fields

27A field is a member that represents a variable associated with an object or class. A field-declaration

28introduces one or more fields of a given type.

29field-declaration:

30

attributesopt field-modifiersopt type variable-declarators ;

31

field-modifiers:

32

field-modifier

33

field-modifiers field-modifier

34

field-modifier:

35

new

36

public

37

protected

38

internal

39

private

40

static

41

readonly

42volatile

43variable-declarators:

44

variable-declarator

45

variable-declarators , variable-declarator

46

variable-declarator:

47

identifier

48

identifier = variable-initializer

49

variable-initializer:

50

expression

51

array-initializer

271

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