Difference between string.Empty and "" [duplicate]
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.
精彩评论