ali raza

C#, .Net , and my thoughts

nullable types in .net framework 2

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

  1. hasvalue (default value is false)
  2. 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.


Dim myint As Nullable(Of Int32)        myint = 32   

     If myint.HasValue Then 

           MsgBox(myint.Value & "has value  ")      


       MsgBox("no value")

        End If


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: