2

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?

Community
  • 1
  • 1
  • Possible duplicate of: http://stackoverflow.com/questions/263191/in-c-should-i-use-string-empty-or-string-empty-or – digEmAll Jul 27 '10 at 09:47

4 Answers4

1

Just coding standard...

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

Andreas Rehm
  • 2,222
  • 17
  • 20
0

They are the same, but looks better.

Pablo Castilla
  • 2,723
  • 2
  • 28
  • 33
0

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

Oded
  • 489,969
  • 99
  • 883
  • 1,009
0

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.

jishi
  • 24,126
  • 6
  • 49
  • 75