Tim on June 3rd, 2008

The IsNullOrEmpty method was added to the String class in the 2.0 Framework, and it makes testing for an empty or null string as easy as a single function call. Instead of having to test the String object if it’s null then checking if it’s empty, this can now be done in one easy method call.
VB.NET

Dim s As String

If String.IsNullOrEmpty(s) Then
  Console.WriteLine("String is null or empty.")
Else
  Console.WriteLine(String.Format("String = {0}", s))
EndIf

This isn’t exactly an earth shattering discovery, but it’s useful nonetheless.

Leave a Reply

You will be able to edit your comment after submitting.