using System;
namespace ConsoleApplication1
{
namespace A
{
class MyClass
{
int value = 1;
public void MyMethod() { System.Console.WriteLine(value); }
}
}
namespace B
{
class MyClass
{
double value = 2.1;
public void MyMethod() { System.Console.WriteLine(value); }
}
}
class Program
{
static void Main(string[] args)
{
A.MyClass a = new A.MyClass();
a.MyMethod(); // 1 출력
B.MyClass b = new B.MyClass();
b.MyMethod(); // 2.1 출력
}
}
}
namespace SampleNamespace
{
class SampleClass
{
public void SampleMethod()
{
System.Console.WriteLine(
“SampleMethod inside SampleNamespace”);
}
}// Create a nested namespace, and define another class.
namespace NestedNamespace
{
class SampleClass
{
public void SampleMethod()
{
System.Console.WriteLine(
“SampleMethod inside NestedNamespace”);
}
}
}
class Program
{
static void Main(string[] args)
{
// Displays “SampleMethod inside SampleNamespace.”
SampleClass outer = new SampleClass();
outer.SampleMethod();
// Displays “SampleMethod inside SampleNamespace.”
SampleNamespace.SampleClass outer2 = new SampleNamespace.SampleClass();
outer2.SampleMethod();
// Displays “SampleMethod inside NestedNamespace.”
NestedNamespace.SampleClass inner = new NestedNamespace.SampleClass();
inner.SampleMethod();
}
}
}