.NET 2.0: Nullable types in VB.NET

After reading two blog posts ([1], [2]) about Nullable Types and consulting the beta documentation for .NET 2.0, here is what works in VB.NET (and not more than that from what I can gather):

Dim i As System.Nullable(Of Integer)
i = 10 ‘ Nothing new here | pun intended ;o)
i = Nothing ‘ OK, so this is new… no more boxing/unboxing required then I guess
If (i.HasValue) Then
Console.WriteLine(i)
Else
Console.WriteLine(“Undefined”)
End If
Dim j As Integer
j = i ‘ Works only if i actually has a value…
i = j ‘ Works always. Obviously, because j, being a regular value type, always has a value, even if unassigned./code]

No ? to indicate a nullable type (or other shorthand), no ?? operator to choose between the value of the nullable type instance or an alternative, etc. Hopefully in a future version.

[1]: Paul Vick’s blog entry

[2]: VB.NET Team blog entry

Let me know what you think, or ask a question...

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

WordPress.com Logo

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

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.