String.Empty和“"”之间的区别是什么? [英] What is the difference between String.Empty and ""

查看:63
本文介绍了String.Empty和“"”之间的区别是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我可以知道String.Empty和之间的区别,现在我们正在使用两者,哪一个更好?请帮助我,



谢谢

Hi,

May I know the difference between String.Empty and "", Nowadays we are using both, Which one is better? Please assist me,

Thank you

推荐答案

在较新的.NET版本中,并不是真的差异,并没有更好的。使用你喜欢的那个:

[ ^ ]

在.NET 2.0版中,创建一个新对象,而 String.Empty 才不是。因此,如果您使用.NET pre 2.0, String.Empty 效率更高:

http://stackoverflow.com/questions/151472/what-is-the-difference-between-string-empty -and-empty-string [ ^ ]
In the newer .NET versions, there is not really a difference, and there is no 'better' one. Use the one you prefer:
http://stackoverflow.com/questions/263191/in-c-should-i-use-string-empty-or-string-empty-or[^]
In .NET pre 2.0, "" creates a new object, while String.Empty does not. So if you use .NET pre 2.0, String.Empty is more efficient:
http://stackoverflow.com/questions/151472/what-is-the-difference-between-string-empty-and-empty-string[^]


在.Net pre 2.0中,创建一个对象,而String.Empty不创建任何对象。因此使用String.Empty更有效。





.Length == 0是最快的选项,但是.Empty使得更简洁的代码。



在.Net的2.0及以上版本中,所有出现的都引用相同的字符串文字。



所以非常相当于.Empty,但仍然不如.Length == 0.



取自以下堆栈Brian R. Bondy的溢出答案: http://stackoverflow.com/a/151481 [ ^ ]
In .Net pre 2.0, "" creates an object while String.Empty creates no object. So it is more efficient to use String.Empty.


.Length == 0 is the fastest option, but .Empty makes for slightly cleaner code.

In version 2.0 and above of .Net, all occurrences of "" refer to the same string literal.

So "" is pretty equivalent to .Empty, but still not as fast as .Length == 0.

Taken from the following Stack Overflow answer of Brian R. Bondy: http://stackoverflow.com/a/151481[^]


String.Empty和之间的差异? [ ^ ]


这篇关于String.Empty和“"”之间的区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆