Namespaces and types have unique names, which are described by fully qualified names that indicate a logical hierarchy. For example, A.B
is the name of the namespace or type B
nested in the namespace or type A
.
In the following code segment, there are nested classes and namespaces. The fully qualified name is indicated as a comment following each entity.
namespace N1 { // N1 class C1 { // N1.C1 class C2 {} // N1.C1.C2 } namespace N2 { // N1.N2 class C2 {} // N1.N2.C2 } }
In the preceding code segment:
N1
is a member of the global namespace. Its fully qualified name is N1.
N2
is a member of N1
. Its fully qualified name is N1.N2.
C1
is a member of the N1
. Its fully qualified name is N1.C1.
C2
is used twice in this code. However, the fully qualified names are unique. The first one is declared inside C1
, thus its fully qualified name is: N1.C1.C2
.
The second is declared inside a namespace N2
; thus, its fully qualified name is N1.N2.C2.
Using the preceding code segment, you can add a new class member C3
to the namespace N1.N2
as follows:
namespace N1.N2 { class C3 {} // N1.N2.C3 }
For more information on namespaces, see Namespaces.