Possible Duplicate:
DateTime “null” value
There are many built-in classes in C# that are not Nullable.
For example, Datetime, sometimes I would like to check if my datatime object is null or not but i am not allowed. How can you insert nullability to datetime class ?
Sure you can make an integer, double, datetime, etc. nullable with a change on the declaration.
BUT
There are two things you need to be aware of.
1) DateTime? and DateTime are not the same data type so, if you do something like this:
The correct way of accesing the value of your nullable type is like this:
2) The second BUT is that you need to ALWAYS check if there is a value before you can use it.
This will throw an exception, “Nullable object must have a value”.
So it’s not that simple as adding the nullable operator, you need to check the property “HasValue” every time you want to use your variable:
Use nullables wisely.