Why DateTime.MinValue and DateTime.MaxValue are not const like int.MinValue and int.MaxValue? Why would C# do that?
I tried to take a look at struct DateTime but couldn't find any constructor that initializes these fields.
Why DateTime.MinValue and DateTime.MaxValue are not const like int.MinValue and int.MaxValue? Why would C# do that?
I tried to take a look at struct DateTime but couldn't find any constructor that initializes these fields.
In .NET only primitive types and strings can be constants.
I tried to take a look at struct DateTime but couldn't find any constructor that initializes these fields.
They are initialized in place: https://referencesource.microsoft.com/#mscorlib/system/datetime.cs,114
In practice, initialization of static fields will be generated in the static constructor:
Fun fact:
In C# you can define decimal constants; however, decimal is not a primitive type. In the background these "constants" will also be compiled as static fields with a special DecimalConstant attribute:
