The most fundamental difference is missing from all previous answers.
Look at the declaration of
string.Empty
;
public static readonly string Empty;
So, strictly speaking this is not a constant. This is a read-only field actually assigned to a constant.
In the sample you provide with your question, "" is an immediate constant, (created every time you place it in the code).
I compared the two for referential equivalence using
object.ReferenceEquals
-- they appeared to be the same, but nothing really guarantee that.
The difference between a constant and read-only field can sometimes be detected during run-time. In particular, this is a reason why string.Empty is not allowed in attribute constructor where an attribute is allowed -- unfortunately! (see Toli's Answer
Difference between String.Empty and ""?[
^]).
In nearly all other cases, using string.Empty is allowed and highly preferred.
I usually consider mixing any kind of immediate constants (by the way, see
this) with code as unacceptable, but make exclusion for code samples and other ad-hoc works.
One advice tip for
not using "" in comparisons: test static predicate
string.IsNullOrEmpty(string)
.
Another advice would be using resources instead of constants, but this is not always practical/possible. In resources, empty strings can be allowed.