Null vs. Nothing
The Nothing
keyword in Visual Basic behaves differently than null
or nil
in most other languages (and all other Elements languages) in that it does niot represent a true ack of a value, but rather the default value of a given type.
For reference types, Nothing
behaves the same as null
/nil
– it gives an unassigned pointer that does not reference a class instance. But for value types, Nothing
will be the equivalent of zero (0
):
Dim x As Int32 = Nothing ' 0
Dim y As Button = Nothing ' Null
' same as
Dim x As Int32 = default(Int32)
Dim y As Button = default(Button)
By contrast, the Null
keyword introduced by Mercury represents a true null
value – a null class reference or a null value in a Nullable value type.
Dim x As Int32 = Null ' invalid, since Int32 can't be Null
Dim x As Int32? = Null ' Null
Dim y As Button = Null ' Null