码迷,mamicode.com
首页 > 其他好文 > 详细

string s = null 和 string s = “”的区别

时间:2014-10-27 12:22:48      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:sp   bs   as   text   字符串   nbsp   class   c   内存   

string s = null; 
表示一个空串,没有占用了空间,不在内存中开辟空间

string s = "";
在内存中开辟空间,但空间中没有值(""也是一个字符串)
表示一个空串,被实列化了,占用了内存空间

null 表示一个空引用,
"" 表示一个空字符串,
string.Empty和“”类似,在内存中分配0个字节 
如果想声明一个初始值为空的字符串变量最好用 string str = string.Empty;

string s = null 和 string s = “”的区别

标签:sp   bs   as   text   字符串   nbsp   class   c   内存   

原文地址:http://www.cnblogs.com/eric-qin/p/4053736.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!