Namespace Syntax


On the basis of our previous namespace discussion, we can deduce the syntax for writing compilation units, using statements, and namespaces. This has been done in Syntax Box 15.1, which makes heavy use of the optional [] brackets because the using statements, namespace definitions, and type definitions in a compilation unit and inside a namespace are optional.

Syntax Box 15.1 Compilation Units, Using Statements and Namespaces

 Compilation_unit::=         [[<using_statement_1>]         [<using_statement_2>]          ...]        [[<Namespace_definition_1>]         [<Namespace_definition_2>]          ...]        [[<Type_definition_1>]         [<Type_definition_2>]          ...] 


 <using_statement> ::=               using <Namespace_name> ; <Namespace_definition>::=              <Short_namespace_name>              {                  [[<using_statement_1>]                   [<using_statement_2>]                    ...]                  [[<Namespace_definition_1>]                   [<Namespace_definition_2>]                    ...]                  [[<Type_definition_1>]                   [<Type_definition_2>]                   ...]              } <Type_definition>           ::= <class_definition>           ::= <struct_definition>           ::= <enum_definition>           ::= <interface_definition>           ::= <delegate_definition> 


  • All <using_statements> must be positioned before any <Namespace_definitions> and any <Type_definitions> within a particular compile unit or namespace.

  • Because a namespace definition can contain other namespace definitions, namespaces can be nested inside each other to any depth you might require.

  • Instead of having to nest namespaces inside each other to write a namespace part, you can write the fully qualified namespace name with each short namespace name part separated from the other parts with periods (.) followed by a pair of curly braces, as shown in the following lines:

     <short_namespace_name_1>.<short_namespace_name_2>....<short_namespace_name_n> graphics/ccc.gif {     <Content_of namespace_part> } 

However, this construct cannot be nested inside another namespace.


C# Primer Plus
C Primer Plus (5th Edition)
ISBN: 0672326965
EAN: 2147483647
Year: 2000
Pages: 286
Authors: Stephen Prata

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: