//命名空間的使用
//.NET Framework类库由命名空间组成。每个命名空间都包含在程序中使用的类型:类,结构,枚举,委托和接口。
using System;
namespace Athrun
{
class test
{
static void Main()
{
A.PrintName a
=new A.PrintName();
a.intro();
B.PrintName b
=new B.PrintName();
b.intro();
}
}
}
namespace A
{
public class PrintName
{
public void intro()
{
Console.WriteLine(
"My name is A");
}
}
}
namespace B
{
public class PrintName
{
public void intro()
{
Console.WriteLine(
"My name is B");
}
}
}

 

 

Code
/*
* Created by SharpDevelop.
* User: Administrator
* Date: 2008/8/26
* Time: 下午 06:56
* 命名空间可以嵌套也可以用別名来取代
* 有时间会因为命名空间过长,用起来不是很方便,所以建议用別名。
* 下面有一個比较怪的例子別名可以直接用来代替到类名.k=A.A1.PrintName;
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/

using System;
using k=A.A1.PrintName;
using m=A.A2;
namespace Athrun
{
class test
{
static void Main()
{
k a
=new k();
a.intro();
m.PrintName b
=new m.PrintName();
b.intro();
}
}
}
namespace A
{
namespace A1
{
public class PrintName
{
public void intro()
{
Console.WriteLine(
"My name is A1");
}
}
}
namespace A2
{
public class PrintName
{
public void intro()
{
Console.WriteLine(
"My name is A2");
}
}
}
}
posted on 2009-03-20 11:06  ★偏翩☆逍遥  阅读(157)  评论(0编辑  收藏  举报