是什么的String.Empty和&QUOT之间的差异;" (空字符串)? [英] What is the difference between String.Empty and "" (empty string)?
问题描述
在.NET中,什么是之间的的String.Empty
的区别和,
,并且是他们互换,或者是有平等的的String.Empty
将确保都没有问题周围的一些基本的引用或本地化问题?
In .NET, what is the difference between String.Empty
and ""
, and are they interchangable, or is there some underlying reference or Localization issues around equality that String.Empty
will ensure are not a problem?
推荐答案
在净pre 2.0,,
创建一个对象,而的String.Empty
创建没有对象。因此,它是更有效地使用的String.Empty。
In .Net pre 2.0, ""
creates an object while String.Empty
creates no object. So it is more efficient to use String.Empty.
Source of information
.Length == 0
是最快的选项,但 .Empty
使得比较清爽,干净code
.Length == 0
is the fastest option, but .Empty
makes for slightly cleaner code.
如前所述@chadmyers,在版本2.0及以上的.Net中,所有的
引用相同的字符串。
As @chadmyers mentioned, in version 2.0 and above of .Net, all occurrences of ""
refer to the same string literal.
所以,
是$ P $相当于 .Empty
ptty的,但还是不一样快 .Length == 0
。
So ""
is pretty equivalent to .Empty
, but still not as fast as .Length == 0
.
请参见的.Net规范了解更多信息,。
这篇关于是什么的String.Empty和&QUOT之间的差异;" (空字符串)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!