X hits on this document

869 views

0 shares

0 downloads

0 comments

203 / 396

C# LANGUAGE SPECIFICATION

Using directives facilitate the use of namespaces and types defined in other namespaces. Using directives impact the name resolution process of namespace-or-type-names (§‎3.8) and simple-names (§‎7.5.2), but unlike declarations, using directives do not contribute new members to the underlying declaration spaces of the compilation units or namespaces within which they are used.

using-directives: using-directive using-directives   using-directive

using-directive: using-alias-directive using-namespace-directive

A using-alias-directive (§‎9.3.1) introduces an alias for a namespace or type.

A using-namespace-directive (§‎9.3.2) imports the type members of a namespace.

The scope of a using-directive extends over the namespace-member-declarations of its immediately containing compilation unit or namespace body. The scope of a using-directive specifically does not include its peer using-directives. Thus, peer using-directives do not affect each other, and the order in which they are written is insignificant.

9.3.1 Using alias directives

A using-alias-directive introduces an identifier that serves as an alias for a namespace or type within the immediately 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. 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.B derives from class N1.N2.A. The same effect can be obtained by creating an alias R for N1.N2 and then referencing R.A:

namespace N3 { using R = N1.N2;

class B: R.A {} }

The identifier of a using-alias-directive must be unique within the declaration space of the compilation unit or namespace that immediately contains the using-alias-directive. For example:

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

Document info
Document views869
Page views869
Page last viewedMon Dec 05 17:20:56 UTC 2016
Pages396
Paragraphs9401
Words133190

Comments