Reputation: 2069
I need to create a System.DateTime
in the settings of my application, now if the field isn't valorized I get this date:
01/01/0001 00:00:00
trying to access as: Properties.Settings.Default.LastUpdated;
I need to compare the value and check if is null. Now the problem is that if the date isn't setted I'll get the value above.
How can I fix this?
Upvotes: 1
Views: 1767
Reputation: 169
DateTime is a struct, so it is a value type not a reference type. As such, it is not nullable.
You may use DateTime.MinValue instead.
if (Properties.Settings.Default.LastUpdated==DateTime.MinValue)
...
Upvotes: 3
Reputation: 2533
If you are never going to use that date than you can put it in a global constant variable and name that variable DateNull. After that just compare them. You can even use nullable types since DateTime is value type so you can have
DateTime? myDate;
If you make a condition like this
if(myDate == null)
it would evaluate to true.
Upvotes: 0