D
Dan Bass
which one do you use and why?
MyString == null || MyString == ""
vs
MyString == null || MyString.Length == 0
MyString == null || MyString == ""
vs
MyString == null || MyString.Length == 0
MyString == null || MyString.Length == 0
MyString == null || MyString.m_stringLength == 0
CultureInfo.CurrentCulture.CompareInfo.Compare(MyString, new String (""),MyString == null ||
which one do you use and why?
MyString == null || MyString == ""
vs
MyString == null || MyString.Length == 0
performance-wise -- String.Empty is simply a language-independent way to
express it
LEBRUN Thomas said:As an aside, String.Empty is completely equivalent to MyString == "",
performance-wise -- String.Empty is simply a language-independent way to
express it
Not exactly
The post of Brad Adams
(http://blogs.msdn.com/brada/archive/2003/04/22/49997.aspx) confirm that
using "" create an object while String.Empty create no onject.
So if you are really looking for ultimately in memory efficiency, use
String.empty
Bye.
-------------------
LEBRUN Thomas
http://morpheus.developpez.com
http://blog.developpez.com/index.php?blog=9
Bob Grommes said: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
which one do you use and why?
MyString == null || MyString == ""
vs
MyString == null || MyString.Length == 0
LEBRUN Thomas said:So if you are really looking for ultimately in memory efficiency, use
String.empty
LEBRUN Thomas said:So if you are really looking for ultimately in memory efficiency, use
String.empty