Why doesn't the following compile in VB.NET?
Dim strTest As String
If (strTest.IsNullOrEmpty) Then
MessageBox.Show("NULL OR EMPTY")
End if
The isEmpty() method checks whether a string is empty or not. This method returns true if the string is empty (length() is 0), and false if not.
In C#, IsNullOrEmpty() is a string method. It is used to check whether the specified string is null or an Empty string. A string will be null if it has not been assigned a value. A string will be empty if it is assigned “” or String. Empty (A constant for empty strings).
The Null value indicates that the Variant contains no valid data. Null is not the same as Empty, which indicates that a variable has not yet been initialized. It's also not the same as a zero-length string (""), which is sometimes referred to as a null string.
IsNullOrEmpty is 'shared' so you should use it that way:
If String.IsNullOrEmpty(strTest) Then
You can actually just compare to an empty string:
If strTest = "" Then
MessageBox.Show("NULL OR EMPTY")
End If
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With