X hits on this document

767 views

0 shares

0 downloads

0 comments

77 / 396

C# LANGUAGE SPECIFICATION

a compile-time error.

3.7 Scopes

The scope of a name is the region of program text within which it is possible to refer to the entity declared by the name without qualification of the name. Scopes can be nested, and an inner scope may redeclare the meaning of a name from an outer scope (this does not, however, remove the restriction imposed by §‎3.3 that within a nested block it is not possible to declare a local variable with the same name as a local variable in an enclosing block). The name from the outer scope is then said to be hidden in the region of program text covered by the inner scope, and access to the outer name is only possible by qualifying the name.

The scope of a namespace member declared by a namespace-member-declaration (§‎9.4) with no enclosing namespace-declaration is the entire program text.

The scope of a namespace member declared by a namespace-member-declaration within a namespace-declaration whose fully qualified name is N is the namespace-body of every namespace-declaration whose fully qualified name is N or starts with N, followed by a period.

The scope of a name defined or imported by a using-directive (§‎9.3) extends over the namespace-member-declarations of the compilation-unit or namespace-body in which the using-directive occurs. A using-directive may make zero or more namespace or type names available within a particular compilation-unit or namespace-body, but does not contribute any new members to the underlying declaration space. In other words, a using-directive is not transitive but rather affects only the compilation-unit or namespace-body in which it occurs.

The scope of a member declared by a class-member-declaration (§‎10.2) is the class-body in which the declaration occurs. In addition, the scope of a class member extends to the class-body of those derived classes that are included in the accessibility domain (§‎3.5.2) of the member.

The scope of a member declared by a struct-member-declaration (§‎11.2) is the struct-body in which the declaration occurs.

The scope of a member declared by an enum-member-declaration  (§‎14.3) is the enum-body in which the declaration occurs.

The scope of a parameter declared in a method-declaration (§‎10.5) is the method-body of that method-declaration.

The scope of a parameter declared in an indexer-declaration (§‎10.8) is the accessor-declarations of that indexer-declaration.

The scope of a parameter declared in an operator-declaration (§‎10.9) is the block of that operator-declaration.

The scope of a parameter declared in a constructor-declaration (§‎10.10) is the constructor-initializer and block of that constructor-declaration.

The scope of a label declared in a labeled-statement (§‎8.4) is the block in which the declaration occurs.

The scope of a local variable declared in a local-variable-declaration (§‎8.5.1) is the block in which the declaration occurs.

The scope of a local variable declared in a switch-block of a switch statement (§‎8.7.2) is the switch-block.

The scope of a local variable declared in a for-initializer of a for statement (§‎8.8.3) is the for-initializer, the for-condition, the for-iterator, and the contained statement of the for statement.

The scope of a local constant declared in a local-constant-declaration (§‎8.5.2) is the block in which the declaration occurs. It is a compile-time error to refer to a local constant in a textual position that precedes its constant-declarator.

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

Document info
Document views767
Page views767
Page last viewedSat Dec 03 03:20:22 UTC 2016
Pages396
Paragraphs9401
Words133190

Comments