8.5.2 Local constant declarations
Collapse the table of content
Expand the table of content
The document is archived and information here might be outdated

8.5.2 Local constant declarations

Visual Studio .NET 2003

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

local-constant-declaration:
const   type   constant-declarators
constant-declarators:
constant-declarator
constant-declarators   ,   constant-declarator
constant-declarator:
identifier   =   constant-expression

The type of a local-constant-declaration specifies the type of the constants introduced by the declaration. The type is followed by a list of constant-declarators, each of which introduces a new constant. A constant-declarator consists of an identifier that names the constant, followed by an "=" token, followed by a constant-expression (Section 7.15) that gives the value of the constant.

The type and constant-expression of a local constant declaration must follow the same rules as those of a constant member declaration (Section 10.3).

The value of a local constant is obtained in an expression using a simple-name (Section 7.5.2).

The scope of a local constant is the block in which the declaration occurs. It is an error to refer to a local constant in a textual position that precedes its constant-declarator. Within the scope of a local constant, it is a compile-time error to declare another local variable or constant with the same name.

A local constant declaration that declares multiple constants is equivalent to multiple declarations of single constants with the same type.

Show:
© 2016 Microsoft