logo
CSharp_Prog_Guide

Использование пространств имен для управления областью действия

Ключевое слово namespace используется для объявления области действия. Возможность создавать области действия в рамках проекта помогает организовывать код и позволяет создавать глобально уникальные типы. В следующем примере в двух пространствах имен, одно из которых вложено в другое, определяется класс, названный SampleClass. Для того, чтобы различать, какой метод вызывается, используется . оператор.

-----

Fully Qualified Names

Namespaces and types have unique titles described by fully qualified names that indicate a logical hierarchy. For example, the statement A.B implies that A is the name of the namespace or type, and B is nested inside it.

In the following example, 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 previous code segment:

Using the previous 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

{

}

}