I've got an IF statement that validates data.
Basically looks like this:
Dim s As String = Nothing
If s Is Nothing Or s.Length = 0 Then
Console.WriteLine("Please enter a value")
End If
Console.Read()
I'd like to check to see if it's nothing first because if I write it this way, it throws a NullReferenceException.
I've thought of re-writing it like this:
If s Is Nothing Then
Console.WriteLine("Please enter a value")
ElseIf s.Length = 0 Then
Console.WriteLine("Please enter a value")
End If
But if I do this I've got the same error message twice and I believe it's less clear what my intent is.
I've also tried throwing parenthesis around the s Is Nothing clause, but it doesn't work.
Is there an elegant what to test if the object is nothing and then test a property of it?