您的位置:知识库 »

C#语法学习二(NameSpace)

作者: Athrun  来源: 博客园  发布时间: 2008-09-05 15:29  阅读: 2565 次  推荐: 0   原文链接   [收藏]  
Code
//命名空間的使用
//.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");
}
}
}
}

0
0
标签:C# NameSpace

热门文章

    最新文章

      最新新闻

        热门新闻