=>In the past I always used "" everywhere for empty string in my codewithout a problem.
=>Now, do you think I should use String.Empty instead of "" (at all
times) ?
=>Which do you find easier to read & why?
=>In the past I always used "" everywhere for empty string in my codewithout a problem.
=>Now, do you think I should use String.Empty instead of "" (at all
times) ?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Dec 24, 2014, 2:37 AM EST
Consequently, there's virtually no difference in using this field or the empty string "" directly and, personally, I nearly always use the latter as it's easier to write.
Note though that if you're testing whether a string is empty or not, then it's more performant to check whether the Length property is zero.
So, instead of this:
if (s == String.Empty)
// or this
if (s == "")
// this is quicker
if (s.Length == 0)
In practice, of course, unless you're doing thousands of such tests, the performance improvement will be negligible.