네임스페이스는 한 세트의 이름을 다른 세트와 별도로 유지하는 방법을 제공하기 위한 것입니다. 네임스페이스 정의는 다음과 같이 네임스페이스 키워드와 네임스페이스 이름으로 시작합니다. -
namespace namespace_name {
// code declarations
} 네임스페이스 정의 -
namespace namespace_name {
// code declarations
} 다음은 C#에서 네임스페이스를 사용하는 방법을 보여주는 예입니다 -
예시
using System;
namespace first_space {
class namespace_cl {
public void func() {
Console.WriteLine("Inside first_space");
}
}
}
namespace second_space {
class namespace_cl {
public void func() {
Console.WriteLine("Inside second_space");
}
}
}
class TestClass {
static void Main(string[] args) {
first_space.namespace_cl fc = new first_space.namespace_cl();
second_space.namespace_cl sc = new second_space.namespace_cl();
fc.func();
sc.func();
Console.ReadKey();
}
} 출력
Inside first_space Inside second_space