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

C# LANGUAGE SPECIFICATION

1An empty statement is used when there are no operations to perform in a context where a statement is

2required.

3Execution of an empty statement simply transfers control to the end point of the statement. Thus, the end

4point of an empty statement is reachable if the empty statement is reachable.

5[Example: An empty statement can be used when writing a while statement with a null body:

6bool ProcessMessage() {…}

7void ProcessMessages() {

8

while (ProcessMessage())

9

;

10}

11Also, an empty statement can be used to declare a label just before the closing “}” of a block:

12void F() {

13

14

if (done) goto exit;

15

16exit: ;

17}

18end example]

1915.4 Labeled statements

20A labeled-statement permits a statement to be prefixed by a label. Labeled statements are permitted in

21blocks, but are not permitted as embedded statements.

22labeled-statement:

23

identifier : statement

24A labeled statement declares a label with the name given by the identifier. The scope of a label is the whole

25block in which the label is declared, including any nested blocks. It is a compile-time error for two labels

26with the same name to have overlapping scopes.

27A label can be referenced from goto statements (§15.9.3) within the scope of the label. [Note: This means

28that goto statements can transfer control within blocks and out of blocks, but never into blocks. end note]

29Labels have their own declaration space and do not interfere with other identifiers. [Example: The example

30int F(int x) {

31

if (x >= 0) goto x;

32

x = -x;

33x: return x;

34}

35is valid and uses the name x as both a parameter and a label. end example]

36Execution of a labeled statement corresponds exactly to execution of the statement following the label.

37In addition to the reachability provided by normal flow of control, a labeled statement is reachable if the

38label is referenced by a reachable goto statement, unless the goto statement is inside a try that includes a

39finally block whose end point is unreachable, and the labeled statement is outside the try.

4015.5 Declaration statements

41A declaration-statement declares a local variable or constant. Declaration statements are permitted in blocks,

42but are not permitted as embedded statements.

43declaration-statement:

44

local-variable-declaration ;

45

local-constant-declaration ;

218

Chapter 15 Statements

115.5.1 Local variable declarations

2A local-variable-declaration declares one or more local variables.

3local-variable-declaration:

4

type local-variable-declarators

5

local-variable-declarators:

6

local-variable-declarator

7

local-variable-declarators , local-variable-declarator

8

local-variable-declarator:

9

identifier

10

identifier = local-variable-initializer

11

local-variable-initializer:

12

expression

13

array-initializer

14The type of a local-variable-declaration specifies the type of the variables introduced by the declaration.

15The type is followed by a list of local-variable-declarators, each of which introduces a new variable. A

16local-variable-declarator consists of an identifier that names the variable, optionally followed by an

17=” token and a local-variable-initializer that gives the initial value of the variable.

18The value of a local variable is obtained in an expression using a simple-name (§14.5.2), and the value of a

19local variable is modified using an assignment (§14.13). A local variable shall be definitely assigned (§12.3)

20at each location where its value is obtained.

21The scope of a local variable declared in a local-variable-declaration is the block in which the declaration

22occurs. It is an error to refer to a local variable in a textual position that precedes the local-variable-

23declarator of the local variable. Within the scope of a local variable, it is a compile-time error to declare

24another local variable or constant with the same name.

25A local variable declaration that declares multiple variables is equivalent to multiple declarations of single

26variables with the same type. Furthermore, a variable initializer in a local variable declaration corresponds

27exactly to an assignment statement that is inserted immediately after the declaration.

28[Example: The example

29void F() {

30int x = 1, y, z = x * 2;

31}

32corresponds exactly to

33void F() {

34

int

x; x = 1;

35

int

y;

36int z; z = x * 2;

37}

38end example]

3915.5.2 Local constant declarations

40A local-constant-declaration declares one or more local constants.

41local-constant-declaration:

42const type constant-declarators

43constant-declarators:

44

constant-declarator

45

constant-declarators , constant-declarator

46

constant-declarator:

47

identifier = constant-expression

219

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