Check nullable types

Friday, November 7th, 2008 | Programming

C# provides a feature for object-relationship mapping. Since a date time field on the database can be empty but the DateTime type in C# can not be set to null, there is a solution called nullable types.

The syntax for is:

DateTime? date;

The problem is, the type of this object is not DateTime, so how it’s possible to check a nullable type? 
It’s quite easy since all nullable types are of the type Nullable<>.  To compare the previous variable date you can use following code:

date.GetType() == typeof(Nullable)

Tags: ,

No comments yet.

Leave a comment