VB.NET compiles:
Dim intResult As Integer = Nothing
C# does not:
int intResult = null; // cannot convert
How the result finally goes to MSIL?
More that than, VB code is OK:
If intResult > Nothing Then
EDIT
OK, MS says:
Assigning Nothing to a variable sets it to the default value for its declared type.
But it tells nothing about Nothing
comparation.
Nothing
in VB.NET is actually equivalent to default(Type)
in C#.
So int intResult = default(int);
is the C# equivalent.
According to the VB.NET Language Reference: "Assigning Nothing to a variable sets it to the default value for its declared type. If that type contains variable members, they are all set to their default values."
Edit: Regarding the comparison to Nothing
:
I'm guessing intResult > Nothing
is interpreted as intResult > 0
, because the compile-time type of intResult
is Integer
, which has a default value of 0. If the type of intResult is not known at compile time (e.g., it is a boxed Integer
), I suspect that this would not compile.
See the Community Content section at the bottom of the VB.NET Language Reference page for a similar example (Nothing < 2
).
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