The foxNET series: The language doesn't matter?

After working in a language like Visual FoxPro for so many years, there are some things that seem so natural that you might not even recognize them as a potential problem. The following code is perfectly useless, but working Visual FoxPro code:

Local obj
obj = Null
If not IsNull(obj) and obj.ToString() <> ""
? "true"
EndIf


Dim obj As Object
obj = Nothing
If obj <> Nothing And obj.ToString() <> "" Then
Console.WriteLine("true")
End If


This time you'll see an exception. Unlike C
and VFP, VB.NET always evaluates all parts of an expression. To avoid problems like this, you have two choices. You can either rewrite the expression to use nested Ifs, or you use the AndAlso operator:


Dim obj As Object
obj = Nothing
If obj <> Nothing AndAlso obj.ToString() <> "" Then
Console.WriteLine("true")
End If