I'd imagine there are two reasons, one for readability, and two for a minor performance boost.
Readability is easy: it's a lot quicker to spot string.Empty
than ""
. Searching for string.Empty
is also generally going to be easier and maybe more accurate than looking for the literal. It also clarifies intent: you didn't just make a typo or forget to finish something, you really did want empty string.
The performance reason is due to interning. You see, the runtime keeps a table of previously used strings so that it can quickly do string comparisons without actually doing a character-by-character check. string.Empty
is already an interned reference to ""
where-as typing the literal may not give you the interned version, thus causing a slight performance hit.
""
but notstring.Empty