String.IsNullOrEmpty (.NET 2.0)

How many times have you written the following string validation code:

if (_name == null || _name.Length == 0)
{
    // ...
}

With .NET 2.0, you can use the static ("Shared" in Visual Basic.NET) utility method String.IsNullOrEmpty to do the same thing:

if (string.IsNullOrEmpty(_name))
{
    // ...
}
Published Wednesday, November 01, 2006 3:16 PM by PSteele

Comments

# re: String.IsNullOrEmpty (.NET 2.0)

I also use(d) it, thinking it's a nice way to shorten your code. However, there seems to be a nasty bug with it. Read http://msmvps.com/blogs/bill/archive/2006/04/04/89234.aspx for more info

Saturday, November 04, 2006 4:21 PM by Arjan Zuidhof

# Followup on String.IsNullOrEmpty

My post about the utility method IsNullOrEmpty elicited an important comment. It seems there is a JIT

Thursday, November 09, 2006 4:01 PM by Patrick Steele's .NET Blog