There is really no difference from the point of view of performance and code generated. In performance tests, they went back and forth, among which one was faster against the other, and only for milliseconds.
In looking at the behind the code, you really do not see any difference either. The only difference is IL
, which string.Empty
use the ldsfld
and ""
operation code uses the ldstr
operation code, but this is just because string.Empty
is static, and both statements do the same thing.
If you look at the set of what is produced, it is exactly the same.
One difference is that if you use the syntax of a switch-case
, you can not write case string.Empty:
because it is not a constant and you will have Compilation error : A constant value is expected
.
As in the example below.
using System;
public class Program
{
public static void Main()
{
string teste = "";
switch (teste)
{
case "":
Console.WriteLine("Case 1");
break;
case String.Empty:
Console.WriteLine("Case 2");
break;
}
}
}
Compilation error (line 14, col 9): A constant value is expected
So user what you find more readable, however. It is subjective and varies from person to person - so I suggest you find out what most people on your team use, and who all do the consistency.
I personally find String.Empty
easier to read.