Value types in dot net framework 2 have some extension that either it take value or not. This extension is called nullable types. For example if we need int32. we declare it as
Dim myint as nullable(of int32)
Now myint can hold value of type int32 if we assign it other wise it contain null value
If we assign myint to 23 it holds integer value
Other wise it contain null value.
This nullable extension in only available to value data type in .net framework 2
The two most important properties of nullable value types are
- hasvalue (default value is false)
- value
both these types are read only.
Before using the variable check its hasvalue property . If it return true it means variable holds some value. Other wise it returns false.
Example
Dim myint As Nullable(Of Int32) myint = 32
If myint.HasValue Then
MsgBox(myint.Value & "has value ")
Else
MsgBox("no value")
End If