说约等于include是不负责任的,在C++的编译过程和C#中的编译过程还是有许多概念上的差别的;所谓的命名空间的引入,using 的确存在引入和参考的过程,在编译时,各编译单元同时编译,在扫描完各编译单元之前具有容错性,待扫描完之后,各编译单元中都会为编译器提交一份各自成员说明,这样以来,凭借说明整个系统中的各编译单元即源文件,在编译后期被处理为一个“大文件”,给人的感觉就是各单元的独立性更强,更符合面向对象的设计编程者的“感觉”。另外,从C到C++再到C#,面向对象的设计编程理念的确在加强,但是,有一点是不会变的,越底层的编译处理越趋于线性处理,即“先声明再使用”;即便是高级编程语言,如是没有运行平台(e.g. .NET),编译过程中,任它任何高级的语言,都要被一层一层被剥成线性的处理过程。当然了,有了运行平台以后,这个编译与从前的编译,以及生成可执行代码的过程也发生了变迁,因为中间多了一层运行平台,这样说来,才能有C#中的引用机制的简易和畅行,e.g: C++: even you have declared a namespace, you still have to "include" instance file body.
#inlucde <istream> using namespace std; C#: Whatever you do, please just give the IDE a message that you want to use it. And the compilor will never be tired as it did in C++ compilor any more.
using System.*.* or using self-defined-namspace
Just do it at you will, Whatever!
Using是指令,编辑的时候有提示啊
uising 用法不止这个。 还可以using(YourOjbect ojb = new YourOjbect()) { }
using System.Windows.Forms;
using System.Text;
using System.Data;StringBuilder sb=....;try:System.StringBuilder results:failed
try:System.Windows.Forms.StringBuilder results:failed
try:System.Text.StringBuilder results:succeed
try:System.Data.StringBuilder results:failed如果有且仅有一个匹配,则成功,否则编译不过(匹配不到指示找不到类型,匹配多个指示不明确的匹配)所以using指令不需要做任何操作,只是当遇到标识符时,作为寻找类型命名空间的数据来源而已
using System.Data.SqlClient
知道要去这里找到类型的定义,完成编译的工作。
是的,不过也要看在什么地方用using了,在命名空间上面用是这样的在方法体里面用的话也有释放内存的作用
C++:
even you have declared a namespace, you still have to "include" instance file body.
#inlucde <istream>
using namespace std; C#:
Whatever you do, please just give the IDE a message that you want to use it. And the
compilor will never be tired as it did in C++ compilor any more.
using System.*.*
or using self-defined-namspace
Just do it at you will, Whatever!
还可以using(YourOjbect ojb = new YourOjbect())
{ }
就像java要导入包一样,
就是引用别人已经写好了的方法,
这样可以减少代码量。