13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>C#</strong> LANGUAGE SPECIFICATIONAbove, N3 already contains a member A, so it is a compile-time error for a using-alias-directive to use thatidentifier. end example] Likewise, it is a compile-time error for two or more using-alias-directives in thesame compilation unit or namespace body to declare aliases by the same name.A using-alias-directive makes an alias available within a particular compilation unit or namespace body, butit does not contribute any new members to the underlying declaration space. In other words, a using-aliasdirectiveis not transitive, but, rather, affects only the compilation unit or namespace body in which it occurs.[Example: In the examplenamespace N3{using R = N1.N2;}namespace N3{class B: R.A {} // Error, R unknown}the scope of the using-alias-directive that introduces R only extends to member declarations in thenamespace body in which it is contained, so R is unknown in the second namespace declaration. However,placing the using-alias-directive in the containing compilation unit causes the alias to become availablewithin both namespace declarations:using R = N1.N2;namespace N3{class B: R.A {}}namespace N3{class C: R.A {}}end example]Just like regular members, names introduced by using-alias-directives are hidden by similarly namedmembers in nested scopes. [Example: In the exampleusing R = N1.N2;namespace N3{class R {}class B: R.A {}}// Error, R has no member Athe reference to R.A in the declaration of B causes a compile-time error because R refers to N3.R, notN1.N2. end example]The order in which using-alias-directives are written has no significance, and resolution of the namespaceor-type-namereferenced by a using-alias-directive is not affected by the using-alias-directive itself or byother using-directives in the immediately containing compilation unit or namespace body. In other words,the namespace-or-type-name of a using-alias-directive is resolved as if the immediately containingcompilation unit or namespace body had no using-directives. [Example: In the examplenamespace N1.N2 {}namespace N3{using R1 = N1; // OK}using R2 = N1.N2;using R3 = R1.N2;// OK// Error, R1 unknown204

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!