Setting it equal to an empty string, represented by two consecutive double quote s: string s = "";Setting it equal to the reserved word null, which is the "zero equivalent" value for the string type (and, as you'll learn later on, for reference types/objects in general): string s = null;
string stu = null,即没分配内存,可以说什么都没有。 而 string stu = "" ,有值,但是空值。
""是空的字符串 它是一个字符串,不过里面没有内容
""分配内存空间
str="";//对象存在了,只不过字串值为空
------------------------------
有点不准确,应该说是分配长度为0的字符串,内存占用不可能是0得
string str=String.Empty;
string str=defalut(String);
string str = null 不给他分配内存空间,
string str = "" 给它分配长度为空的字符串的内存空间
""是空的字符串 它是一个字符串,不过里面没有内容
str = "" 是把string 对象的值设置为空一般建议使用 string strTmp = string.Empty;
string = null 只是在堆栈上分了引用地址,但是托管堆上是空的。string = "" 两者都分配了,只是堆上的内容是"",所以string = null是没有任何指向任何对象的,是个空对象。
str="";//对象存在了,只不过字串值为空
string str = string.Empty 等价于 str = "" ;//表示为对象分配了内存,但值为空
实属没有意义。
string是 netFramework的内置类型 其优化方式本身就不符合类的一些规则。
Setting it equal to an empty string, represented by two consecutive double quote
s:
string s = "";Setting it equal to the reserved word null, which is the "zero equivalent" value for the
string type (and, as you'll learn later on, for reference types/objects in general):
string s = null;
而 string stu = "" ,有值,但是空值。
"",表示抽屉存在,只不过抽屉里面啥没有。
string str=""; 的实质是 char *ps=""; 或 char *ps="\0";
也就是说
string str=null;表示str是一个为0的指针。不分配任何内存空间。
string str=""; 表示str指向首元素为0(字符串结束标志)的字符数组。会分配内存空间,但是该内存空间的首位为0。
复杂的说呢见楼上各位。
是相等的。
你可以测试string.Empty.Equals("")和string.Empty.Equals(null)
string str ="" 分配字节为0的内存。
这年头笔试都喜欢来这个
str=""也等价与str.length=0;
string str = "" 给它分配长度为空字符串的内存空间.
string stu = " " ,有值,长度为0,但是空值
我前几天做的时候用这个了!
string str=null
取str.length的时候就对象未设置成引用的实例
string str=""的时候str.length==0了
string s = string.Empty;
Empty是String类的静态方法,就意味这不会反复申请内存用Microsoft FxCop软件检测 string s = ""; 是个警告吧,说明这个方法不好;string s = null; //将s指向空,和object obj = null是同个意思,Object是所有类的父类
string str = "" 给它分配长度为空字符串的内存空间.