WTF!

A typical WTF :)

Public Sub New(ByVal str As String)
    If (str = String.Empty Or str = Nothing Or String.IsNullOrEmpty(str) Or Len(str) = 0) Then
        str = ""
    End If
    Me._str = str
End Sub

Comments

# re: WTF!

Tuesday, December 12, 2006 6:28 AM by Mladen

besides the obvious WTF,

does VB evalate all of the conditions in the or?

because C# stops when it reaches the first true.

so if

str is Nothing and VB evaluates them all

then Len(str) = 0 will throw an exception.

won't it?

# re: WTF!

Tuesday, December 12, 2006 6:45 AM by israel aece

Hello Mladen,

VB.NET has a short-circuit operator: OrElse and AndAlso, so in OrElse case, if the first condition is True, the second is not evaluated. But all conditions in above code are making the same verification.

If you need to test thenstring value, you only need to use the static method IsNullOrEmpty of String class.

Thanks for comment.