A value type such as
System.DataTime
cannot accept
null
or
DBNull
value. This type should also have a value.
There is a popular method of using
DateTime.MinValue
. This is nothing like yes another programming fraud.
MinValue
represents the time point of 00:00:00.0000000, January 1, 0001. Why on Earth this time should be considered as invalid (while a time of one millisecond later is valid)?!
I think there is only one decent solution: use a
nullable type derived from
DataTime
.
System.DataTime? MyDateTime;
MyDateTime = null;
MyDateTime = DateTime.Now;
For more information on nullable types, see
http://msdn.microsoft.com/en-us/library/1t3y8s4s.aspx[
^].
A primary purpose of introduction of nullable types was handling of the situations similar to the one described in the present Question.
—SA