开发者

The benefits of using String.Empty [duplicate]

开发者 https://www.devze.com 2023-01-16 04:24 出处:网络
This question already has answers here: Closed 12 years ago. Possible Duplicate: In C#, should I use string.Empty or String.Empty or “” ?
This question already has answers here: Closed 12 years ago.

Possible Duplicate:

In C#, should I use string.Empty or String.Empty or “” ?

I just don't understand the benefits of using String.Empty over "". Aside it being strongly typed its longer.

So please, why should I be u开发者_运维问答sing this?


As has been mentioned string.Empty creates no object where as "" will create an object (albeit pulled out of the pool). The performance difference is minimal but the question should be what is more readable. I take the stance that string.Empty sticks out more than "" and I can clearly see the intent of the declaration (string.Empty vs null). Regardless of your choice you should be consistent throughout your code base.

String.Empty vs ""


There is no meaningful difference. See these (and other) questions elsewhere on SO:
In C#, should I use string.Empty or String.Empty or "" to intitialize a string?
Why is string.Empty more efficient than "" in .Net
String.Empty versus ""
What is the difference between String.Empty and “” and null?
Which should I use for empty string and why?
Difference between string.Empty and ""

0

精彩评论

暂无评论...
验证码 换一张
取 消