It's a trade off between a slight advantage in clarity vs a slight advantage
in performance (actually MyString == "" has something more than a slight
performance advantage in theory, but in practice it isn't that often that it
amounts to so much of a difference that a user would actually notice).
I personally use MyString.Length == 0 out of habit, as I think it's pretty
self-explanatory.
As an aside, String.Empty is completely equivalent to MyString == "",
performance-wise -- String.Empty is simply a language-independent way to
express it. It would also have the advantage of being utterly clear, except
that in my experience many developers seem fuzzy on exactly what Empty
really means. I mean, *I'm* clear on what it means yet when I first
encountered String.Empty I felt it necessary to check the docs to make sure
it meant what I thought it did. And most languages have an unambiguous way
to express an empty string as a constant similar to "", so I prefer "" as
clearer than String.Empty.
--Bob
"Dan Bass" <danielbass [at] postmaster [dot] co [dot] uk> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
which one do you use and why?
MyString == null || MyString == ""
vs
MyString == null || MyString.Length == 0