X hits on this document

749 views

0 shares

0 downloads

0 comments

135 / 396

C# LANGUAGE SPECIFICATION

Otherwise, starting with the namespace in which the simple-name occurs, continuing with each enclosing namespace (if any), and ending with the global namespace, the following steps are evaluated until an entity is located:

If the namespace contains a namespace member with the given name, then the simple-name refers to that member and, depending on the member, is classified as a namespace or a type.

Otherwise, if the namespace has a corresponding namespace declaration enclosing the location where the simple-name occurs, then:

If the namespace declaration contains a using-alias-directive that associates the given name with an imported namespace or type, then the simple-name refers to that namespace or type.

Otherwise, if the namespaces imported by the using-namespace-directives of the namespace declaration contain exactly one type with the given name, then the simple-name refers to that type.

Otherwise, if the namespaces imported by the using-namespace-directives of the namespace declaration contain more than one type with the given name, then the simple-name is ambiguous and a compile-time error occurs.

Otherwise, the name given by the simple-name is undefined and a compile-time error occurs.

7.5.2.1 Invariant meaning in blocks

For each occurrence of a given identifier as a simple-name in an expression or declarator, every other occurrence of the same identifier as a simple-name in an expression or declarator within the immediately enclosing block (§‎8.2) or switch-block (§‎8.7.2) must refer to the same entity. This rule ensures that the meaning of a name is always the same within a block.

The example

class Test { double x;

void F(bool b) { x = 1.0; if (b) { int x; x = 1; } } }

results in a compile-time error because x refers to different entities within the outer block (the extent of which includes the nested block in the if statement). In contrast, the example

class Test { double x;

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

Document info
Document views749
Page views749
Page last viewedFri Dec 02 18:10:03 UTC 2016
Pages396
Paragraphs9401
Words133190

Comments