Tired of object referece is null errors?  The new Nullable<T> generic type is here to make your life easier.  In continuing our discussion with generics from yesterday, this new type allows you to have value types which accept null values.
 
Here are couple of examples of Nullable declarations:
Nullable<int> x = 123;
Nullable<int> y = null;

Both lines are ok and will not throw an exception.
 
There are many ways you can access the type safely.
 
To check if the type has a value (i.e. not null), simply use the HasValue property.
 
// check to see if x has  a value
if (x.HasValue)
{
    int myInt = x.Value;
}
 
Or you can access it safely using the static GetValueOrDefault(Nullable<T>) method:
 
int myInt = Nullable.GetValueOrDefault(y);
 
The above method will return the default value for the alue type int (in this case 0).
 
I believe the Nullable<T> type will prove to be quite valueable, especially when doing data access.

Read the complete post at http://www.dotnettipoftheday.com/blog.aspx?id=219