Nullable Types in VB.NET?
Nullable types can be used in VB.NET same as in C#.
You can't assign Null
, Nothing
or DBNull
to a bare Integer
in VB but you can use a Nullable(Of Integer)
instead:
Dim x As Integer? = Nothing
Alternatively, it sometimes (but rarely) makes sense to box the integer value in an Object
(which can be Nothing
).
VB.Net does have nullable types, they can be declared in the following two different ways.
Dim iNullable As Integer?
or
Dim iNullable As Nullable(Of Integer)