Be careful with String.IsNullOrEmpty

By jpsmit
September 18, 2006

While I ran FxCop over someone else’s code it pointed me to a String method I didn’t know about: IsNullOrEmpty.

This method is new in .NET 2.0 and FxCop supplies the following description with it:

“To test for empty strings, check if String.Length is
equal to zero. Constructs such as “”.Equals(someString)
and String.Empty.Equals(someString) are less efficient
than testing the string length. Replace these with
checks for someString.Length == 0.”

Sounds like a nice addition, but then I ran into this blog which tells me to be very careful with it:

Comments: 0

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Recent Posts
  • Recent Comments
  • Archives
  • Categories
  • Meta