开发者

Difference between string.Empty and "" [duplicate]

This question already has answers here: 开发者_如何学C Closed 12 years ago.

Possible Duplicate:

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

Is there any difference in c# between the following declarations...

private string m_port = string.Empty;

or...

private string m_port = "";

Is it just coding standard that makes it look neater?


Just coding standard...

http://msdn.microsoft.com/en-US/library/system.string.empty%28VS.80%29.aspx


They are the same, but looks better.


The main difference is one of semantics - string.Emtpy says that you meant to have an empty string. "" might be a mistake (" ", for instance).


Since String.Empty is an instance it should remove the overhead of the object creation, however I think a parser should be smart enough to figure this out.

All string literals is also pulled from an object pool I believe, so the object creation might not even take place.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜