王立平--string.Empty

String.Empty 字段  .NET Framework 类库  表示空字符串。此字段为仅仅读。命名空间:System  程序集:mscorlib(在 mscorlib.dll 中)  protected string loginId = String.Empty;  protected string loginId = ""; 

 string.Empty 不分配存储空间  "" 分配一个长度为空的存储空间  所以一般用string.Empty 

 为了以后跨平台,还是用string.empty 

 在 C# 中,大多数情况下 "" 和 string.Empty 能够互换使用。

比方:  string s = "";  string s2 = string.Empty;  if (s == string.Empty) {  //  }  if语句成立 

 判定为空字符串的几种写法,依照性能从高到低的顺序是:  s.Length == 0 优于 s == string.Empty 优于 s == ""  您关于String.Empty和Null的问题是这种,这两个都是表示空字符串,当中有一个重点是string str1= String.Empty和 string str2=null 的差别,这样定义后,str1是一个空字符串,空字符串是一个特殊的字符串,仅仅只是这个字符串的值为空,在内存中是有准确的指向的,string str2=null,这样定义后。仅仅是定义了一个string 类的引用。str2并没有指向不论什么地方,在使用前假设不实例化的话,都将报错。textBox1.Text的值为零长度字符串 ""。

  平台  Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition  .NET Framework 不是每个平台的所有版本号提供支持。 

版权声明:本文博客原创文章,博客,未经同意,不得转载。

posted @ 2015-07-20 15:32  mengfanrong  阅读(145)  评论(0编辑  收藏  举报