Mega Code Archive

 
Categories / VB.Net / Language Basics
 

Check if nullable is null

Option Explicit On Option Strict On Class MyClass1     Public numericValue As Integer?     Public boolValue As Boolean? = True     Public Function GetIntFromDatabase() As Integer?         Return numericValue     End Function     Public Function GetBoolFromDatabase() As Boolean?         Return boolValue     End Function End Class Module Program     Sub Main()         Dim dr As New MyClass1()         Dim i As Integer? = dr.GetIntFromDatabase()         If (i.HasValue) Then             Console.WriteLine("Value of 'i' is: {0}", i.Value)         Else             Console.WriteLine("Value of 'i' is undefined.")         End If         Dim b As Boolean? = dr.GetBoolFromDatabase()         If (b.HasValue) Then             Console.WriteLine("Value of 'b' is: {0}", b.Value)         Else             Console.WriteLine("Value of 'b' is undefined.")         End If     End Sub End Module