.Net 2.0: Nullable
January 7th, 2008
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) {...}





