tags:

views:

36

answers:

2

I have a DateTime struct I use, and sombody commented out the part where it was created (but not declared) When I was using it, myDate.DayOfWeek == DayOfWeek.Monday returned true.

If the part where it is created is commented out, how can it tell me it's monday, instead of throwing some exception?

+5  A: 

DateTime is a value type (a struct), and therefore it always has a value. It cannot be null like a reference type. When a variable of a value type is not assigned yet, it's initialized to some default value depending on the type. The default value for DateTime just happens to be a Monday in the calendar .NET uses.

Of course, calendars have changed many times in the past and applying our current calendar more than a few hundred years into the past just doesn't work, but to .NET, it's a Monday.

Matti Virkkunen
+3  A: 

DateTime is a struct which means that it has to have some sort of default value. The default value for DateTime is DateTime.MinValue, which is 1 January 0001, which was a monday.

LukeH
+1, yes. Well, that settles it. The first day of the week has to be Monday, not Sunday.
Hans Passant