Bhu*_*dey 4 .net c# asp.net string
任何人都可以告诉我,我没有使用系统名称空间,但字符串可用作字符串hello ="Hello"; 并且不会抛出任何编译时错误
但是,如果我写大写字符串,它就不可用.
sealed class SealedClass
{
public void PrintSealed()
{
string hello = "Hello";
}
}
Run Code Online (Sandbox Code Playgroud)
您不需要using关键字来使用库的"片段".该using关键字只是为了更容易地引用命名空间内的类型.
当你写作
using System;
.... ...
String hello = "Hello";
Run Code Online (Sandbox Code Playgroud)
编译器将其替换为
System.String hello = "Hello";
Run Code Online (Sandbox Code Playgroud)
但你可以直接写
System.String hello = "Hello";
Run Code Online (Sandbox Code Playgroud)
没有using System.但这很痛苦:-)
然后string是别名System.String,所以当你编写时string,C#编译器将其替换为System.String(MSDN).
请注意,要使用库,您仍然需要引用它,但是您没有从代码中引用它,您从项目中引用它,这样做Add Reference.该mscorlib库(组装)被自动引用(你不能删除参考)
这与Microsoft Visual C/C++略有不同,其中通常有类似于:
#pragma comment(lib, "somelibrary")
Run Code Online (Sandbox Code Playgroud)
这是链接器包含.lib文件(库)的指令.在Visual C/C++中,您通常不需要显式包含库,只需包含其包含该命令的头,并且链接器将自动链接库.