=>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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Dec 24, 2014, 7:37 AM
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.