I have been looking through the DateTime structure and I am slightly confused.
My understanding with structs is that you cannot assign ‘default values’ of fields. If the default constructor of a struct is used (which is not something that you can control), then any fields will be initialized using the default values of their value type.
This is all good and well, but why then is the default value of the ‘Days’ property of a DateTime equal to 1? How do they pull that off?
William
You need to understand the difference between fields and properties.
The fields are all initialized to 0, but the properties can do what they like with those fields. Sample:
Now obviously
DateTimeis a smidge more complicated than this, but it gives the right idea 🙂 Imagine what “ADateTimewith the field explicitly set to 0″ would mean… the “default”DateTimejust means exactly the same thing.