CJ7
CJ7

Reputation: 23275

How to use IsNullOrEmpty in VB.NET?

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

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

Upvotes: 26

Views: 143060

Answers (3)

Tomq
Tomq

Reputation: 1125

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

If String.IsNullOrEmpty(strTest) Then

Upvotes: 75

Rolf Bjarne Kvinge
Rolf Bjarne Kvinge

Reputation: 19335

You can actually just compare to an empty string:

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

Upvotes: 11

moribvndvs
moribvndvs

Reputation: 42497

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

Upvotes: 9

Related Questions