Use whichever you find most readable.
I challenge anyone to find a realistic application where there's a significant performance difference... it just won't happen. However, different people find different approaches more readable.
Personally, I'm a ""
person. I find it less cluttered, and I've never encountered a problem where I actually used " "
(or something similar) accidentally. (That's one of the objections frequently raised.)
If you prefer string.Empty
, I'm certainly not going to claim you're "wrong". I would suggest, however, that if you're working on a team you discuss it to find out what most people think is more readable, and stick to that. Consistency is generally a good thing.
EDIT: Just to allay some fears which might be induced by the claim that "" will create a new string... it may create a new string once (possibly per AppDomain
, possibly per process; I'm not sure and it really doesn't matter). It won't create a new string every time you use it. For example, consider this code:
public void Foo()
{
string x = "";
for (int i=0; i < 10000000; i++)
{
string y = "";
// Do something here
}
string z = "";
}
You are guaranteed that x
, y
and z
will refer to the same string. At most, invoking Foo
will mean a single empty string is created, and only the first time you call it, and only if you haven't used an empty string literal anywhere else in the program yet. The code above is not going to create 10 million new strings.