How to use IsNullOrEmpty in VB.NET?

135.3k Views Asked by At

Why doesn't the following compile in VB.NET?

Dim strTest As String
If (strTest.IsNullOrEmpty) Then
   MessageBox.Show("NULL OR EMPTY")
End if
3

There are 3 best solutions below

0
On BEST ANSWER

IsNullOrEmpty is 'shared' so you should use it that way:

If String.IsNullOrEmpty(strTest) Then
4
On

You can actually just compare to an empty string:

If strTest = "" Then
    MessageBox.Show("NULL OR EMPTY")
End If
4
On

String.IsNullOrEmpty is a shared (or static, in C#) method.

Dim strTest As String
If (String.IsNullOrEmpty(strTest)) Then
   MessageBox.Show("NULL OR EMPTY")
End if