rulururu

post .Net 2.0: Nullable

January 7th, 2008

Filed under: .NET — Kai @ 8:46 am

One of the “late breaking” features in .Net 2.0 is what is known as “Nullable Types” (Nothing in VB.NET).
In former times I defined a Generic struct or class (C++: “Template Class”)

struct Nullable<t>
{
public bool HasValue;
public T Value;
}
Nullable<int> x = new Nullable<int>(5);
bool b = x.HasValue();

Since .Net 2.0 you simply can write:

int? x = 5;

which is much simpler. Similarly, rather than needed to write a null test as:

if (x.HasValue) {...}

you can use a familiar comparison to null:

if (x != null) {...}

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

ruldrurd
Powered by WordPress, Content and Design by Kai Bellmann
Entries (RSS) and Comments (RSS)