好听的空间名字:c#中的名字空间

c#中的名字空间

名字空间(namespace)用来组织程序的结构
namespace关键字:声明一个范围组织代码
格式:
namespace name
{
type declaration(包括calss,struct,enum,delegate,interface)
}
实例:
using System;
using System.Collections.Generic;
using System.Text;
namespace aa //声明名字空间aa
{
public class bb //定义类bb
{
public static void Main()
{
cc.dd.ee();
}
}
namespace cc //声明名字空间cc
{
public class dd //定义类dd
{
public static void ee()
{
Console.WriteLine("hello");
Console .Read ()
}
}
}
}
运行结果:

using 关键字的两个用途
1.可以为名字空间创建一个别名
2.允许在空间中使用类型
3.不允许访问嵌套的名字空间中的名字空间
语法格式:
using 名字空间的别名 = 起名的名字空间,起别名的类的名称
定义名字空间中的using别名
using System;
using System.Collections.Generic;
using System.Text;
using aa = bb.cc.dd;
namespace bb.cc
{
public class myclass
{
public static void donothing()
{
}
}
namespace dd
{
public class ee
{
public static void ff()
{
Console.WriteLine("hello");
Console.Read();
}
}
}
}
public class gg
{
public static void Main()
{
aa.ee.ff();
}
}
运行结果:

名字空间的应用实例:
namespace aa.bb.cc
{
public class dd
{
string m_message;
public dd()
{
m_message = "hello";
}
public string message
{
get
{
return m_message;
}
set
{
m_message = value;
}
}
}
}
客户程序:
using system;
using aa.bb.cc;
class hello
{
public static void Main()
{
dd m=new dd ();
Console.WriteLine("m.message");
}
}
运行结果:

换行输出: system.console.writeline()
换行输出: system.console.readline()
不换行输出: system.console.write()
不换行输出: system.console.read()
.NET框架的几个空间名:
system 定义数据累年高兴和数据转换
system.collections 定义列表,队列,位数组合字符串表
syetem.data 定义ado.net数据结构
system.drawing 提供对基本图形的访问
system.io 读写数据流和文件
system.net 提供对windiws网络功能的访问
system.net.sockets 提估堆windows套接字的访问
system.runtime.remoting 提供对windows分布式计算机平台的访问
system.security 对clr安全许可系统的访问
system.text 对字符编码的处理
system.threading 多线城编程
system.timers 在只歌德是间隔触发事件
system.web 浏览器和web服务器功能
system.web.mali 发送电子邮件
system.windows.forms 创建使用标准windows图形借口的基于windows的应用程序
system.xml 提供对mxl稳当的支持
c#中的程序的注释:
1.// 注释,位于//后面的都认为是注释
2./* */位于中间的都为注释
3./// 可以转哈成xml文件
书写c#程序注意的几个问题:
1.使用using关键字指明引用的空间名称
2.使用namespace申明名称空间
3.使用calss申明类
4.一个扩展名为cs的问可以包含多个类,一个引用程序可以包含多个cs斍
Tags:  qq空间名字 空间的名字 qq空间的名字 好听的空间名字

延伸阅读

最新评论

发表评论