Mega Code Archive

 
Categories / VB.Net / Language Basics
 

Main with Nullable (Of T)

Class MyClass1     Public numericValue As Nullable(Of Integer)     Public boolValue As Nullable(Of Boolean) = True     Public Function GetIntFromDatabase() As Nullable(Of Integer)         Return numericValue     End Function     Public Function GetBoolFromDatabase() As Nullable(Of Boolean)         Return boolValue     End Function     Public Shared Sub Main()         Dim dr As New MyClass1()         Dim i As Nullable(Of 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 Nullable(Of 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 Class