Differences between vb.net and c#
Clever Code
22
Posts
14
Posters
19
Views
1
Watching
-
The thing is that vb.net evaluates the comparison to
Nothing
when one of the operands isNothing
. And something like:If Nothing Then
End If
Is valid, even if you specify
Option Strict On
But is Nothing True or Nothing False in the VB world? :p
-
Do you think this two pieces of code are the same? C#
private string f() { System.Nullable<System.Int32> a = null; System.Nullable<System.Int32> b = 7; if (a != b) { return "apple"; } else { return "orange"; } }
Function f() As String Dim a As System.Nullable(Of System.Int32) = Nothing Dim b As System.Nullable(Of System.Int32) = 7 If a <> b Then Return "apple" Else Return "orange" End If End Function
I didn't think it is a problem. In VB6 you must use the IS operator to check for Nothing values: If Var IS Nothing Then .... And I am almost sure that it was documented and the behavior you mention of comparing 2 variables when some o both are Nothing can give wrong results. Best regards, Mauro H. Leggieri