Sven's Blog

MemoryStream ms = new MemoryStream(MyBrain); // Management and technology considerations

Subscriptions

<November 2008>
SuMoTuWeThFrSa
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456

News

Welcome to my spot on the 'Net. I am the Principal Consultant at Adduxis, a management and IT consulting firm. This blog will provide you with some (hopefully) useful information and links to tidbits found on the Internet.

Navigation

Post Categories

Microsoft Bloggers

.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.

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

posted on Thursday, April 07, 2005 10:16 PM by SvenAelterman

Powered by Community Server, by Telligent Systems