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.

Chapter 16 Namespacesusing-directives:using-directiveusing-directives using-directiveusing-directive:using-alias-directiveusing-namespace-directiveA using-alias-directive (§16.3.1) introduces an alias for a namespace or type.A using-namespace-directive (§16.3.2) imports the type members of a namespace.The scope of a using-directive extends over the namespace-member-declarations of its immediatelycontaining compilation unit or namespace body. The scope of a using-directive specifically does not includeits peer using-directives. Thus, peer using-directives do not affect each other, and the order in which they arewritten is insignificant.16.3.1 Using alias directivesA using-alias-directive introduces an identifier that serves as an alias for a namespace or type within theimmediately enclosing compilation unit or namespace body.using-alias-directive:using identifier = namespace-or-type-name ;Within member declarations in a compilation unit or namespace body that contains a using-alias-directive,the identifier introduced by the using-alias-directive can be used to reference the given namespace or type.[Example: For example:namespace N1.N2{class A {}}namespace N3{using A = N1.N2.A;}class B: A {}Above, within member declarations in the N3 namespace, A is an alias for N1.N2.A, and thus class N3.Bderives from class N1.N2.A. The same effect can be obtained by creating an alias R for N1.N2 and thenreferencing R.A:namespace N3{using R = N1.N2;}class B: R.A {}end example]The identifier of a using-alias-directive must be unique within the declaration space of the compilation unitor namespace that immediately contains the using-alias-directive. [Example: For example:namespace N3{class A {}}namespace N3{using A = N1.N2.A;}// Error, A already exists203

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

Saved successfully!

Ooh no, something went wrong!