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的值为零长度字符串 ""。

http://www.cnblogs.com/SAL2928/archive/2007/07/16/820437.html

其他几个相关链接:

http://codebetter.com/blogs/brendan.tompkins/archive/2003/10/14/2585.aspx

String.Empty vs. ""

So, I just converted a bunch of code that used "" as an empty string like this:

if(myString == "") anotherString = "";

to

if(myString.Equals(String.Empty))   anotherString = String.Empty;

and I'm wondering if I did the right thing, using String.Empty. I hate having quoted strings in code and prefer to stay away from them whenever possible.   This generally leads to code that is more strongly typed, and easier to maintain, so using String.Empty intuitively feels better than ““.   But, I've actually found a concrete reason to use String.Empty - I did some research and found that in a test, str.Equals(String.Empty) is faster than comparing to ""!    Well, okay. Research isn't the right word, “Doing one google search and accepting on faith the first post I saw” is slightly more accurate.   I even created a little graph of the claims in this post here, that String.Empty is faster.   I'm too lazy to do the test myself, so if you want to verify this, knock yourself out.   I do love making graphs though.

也就是说 判断字符串是否为空best的方法就是     str.Length==0 !

http://blogs.msdn.com/brada/archive/2003/04/22/49997.aspx

http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_frm/thread/a129a0cd26227ace/3a5b5f69e03b5ad4?hl=en&lr=&ie=UTF-8&oe=UTF-8&rnum=1&prev=/groups%3Fq%3DString.Empty%2Bvs%2B%2522%2522%2Bdotnet%26hl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26selm%3DOqSV8eZ7BHA.2128%2540tkmsftngp03%26rnum%3D1#3a5b5f69e03b5ad4

转载于:https://www.cnblogs.com/dragonlhf/archive/2007/11/13/958129.html

String.Empty,NULL和的区别相关推荐

  1. C#中NULL,,DBNULL,String.Empty,Convert.IsDBNull()的区别

    C#中的空值的判断较麻烦,不象在VB6中那么简单,这些各种空值的判断和理解对不熟悉的人来说,可能很麻烦,现就我在使用过程中的一点体会和大家共同分享. (1)NULL null 关键字是表示不引用任何对 ...

  2. string.empty , , null 以及性能的比较

    一:这种结论,个人觉得仍然存疑  http://www.cnblogs.com/wangshuai901/archive/2012/05/06/2485657.html  1.null null 关键 ...

  3. String.Empty和的区别

    1.共同点 Empty是string类中的一个静态的只读字段,他的定义 public static readonly String Empty = ""; string.Empty ...

  4. NULL,,String.Empty三者在C#中的区别

    (1)NULL null 关键字是表示不引用任何对象的空引用的文字值.null 是引用类型变量的默认值.那么也只有引用型的变量可以为NULL,如果int i=null,的话,是不可以的,因为Int是值 ...

  5. string.Empty和null三者的区别

    本文来讨论"",string.Empty和null三者到底有什么区别 这是一个及其常见的问题,网上已经有关于这个问题的很多讨论.但是我觉得都是不求甚解,有一些还是在误导别人.下面我 ...

  6. ,string.Empty和null三者的区别

    这是一个及其常见的问题,网上已经有关于这个问题的很多讨论.但是我觉得都是不求甚解,有一些还是在误导别人.下面我来说下我对这三者的理解,如有错误的地方请大家及时指正. 一:""与st ...

  7. C#中的DBNull、Null、和String.Empty解释

    1.对DBNull的解释:     该类用于指示不存在某个已知值(通常在数据库应用程序中).     在数据库应用程序中,空对象是字段的有效值.该类区分空值(空对象)和未初始化值(DBNull.Val ...

  8. C#中的DBNull、Null、String.Empty和“”

    null可赋值任何变量,将变量置为空  DBNull只用于DataRow对象,表示数据库中的空值  String.Empty是0长度字串  Convert.IsDBNull判断是否为DBNull DB ...

  9. php中is null,php中empty(), is_null(), isset()函数区别

    empty(), is_null(), isset()真值表(区别) 我们先来看看这3个函数的功能描述 www.111cn.net isset 判断变量是否已存在,如果变量存在则返回 TRUE,否则返 ...

最新文章

  1. 近期要推出的ISA2006系列文章
  2. 如何实现php自动备份数据库,使用php自动备份数据库表的实现方法
  3. php 如何将字体转为gb,利用php怎么将utf-8与GB2312相互转换
  4. 创意or鸡肋?亚马逊想让智能音箱“手机”化
  5. IntelliJ IDEA下的使用git
  6. linux合并pdf命令,LINUX下合并PDF
  7. 商淘软件已成为ThinkPHP商城系统之标杆产品
  8. Matplotlib——绘制散点图并连线
  9. AUTOSAR基础篇之StbM
  10. 不需要死记硬背,看一遍就能记住单词的意思,一起了解单词背后的有趣故事(6)
  11. 阿卡迪亚大学计算机专业好考吗,加拿大阿卡迪亚大学热门专业介绍
  12. 第二讲 中国古代密码艺术
  13. 揭秘青提WiFi分销小程序到底有多赚钱?商家的宝贝代理的吸金利器
  14. 第三次工业革命(四)
  15. 智能网联封闭测试场和开放道路测试政策情况全扫描(2022版)
  16. js时间分割——主要用途——租赁合同时间计算(两种时间分割方式,可以按月,季,年分割)
  17. [RFID]射频卡介绍(一)ID-EM4100
  18. 解线性方程组的直接方法:LU分解法及其C语言算法实现
  19. spaceclaim简单建模5
  20. 同个局域网内的A,B两个电脑主机,A能PING通B电脑,B无法PING通A 电脑,双方均能学习到对方ARP地址

热门文章

  1. Spring Boot项目优雅的全局异常处理方式(全网最新)
  2. 一个XP使用者眼中的Windows 7
  3. FullCalendar 二:FullCalendar日历插件说明文档
  4. Joomla!程序中加载JS和CSS的方法
  5. Kinect for Windows V2和V1对比开发___彩色数据获取并用OpenCV2.4.10显示
  6. 【AI视野·今日CV 计算机视觉论文速览 第218期】Fri, 11 Jun 2021
  7. Sting中方法举例
  8. 0309随堂笔记 银行转帐功能 对向封装 1615278206
  9. 如何修改和配置idea编辑器的编码
  10. 0924html小测答案