C# - Why are DateTime.MinValue and MaxValue not compile-time constants?

You cannot define a DateTime constant (or structs). From MSDN allowed types for const are.

You cannot define a DateTime constant (or structs). From MSDN allowed types for const are: One of the types: byte, char, short, int, long, float, double, decimal, bool, string, an enum type, or a reference type.

1 thanks, this answers my actual question! – Alex Jul 28 at 10:06.

Workaround: Use a nullable as parameter. IMO this is cleaner anyways since the special value is clearly different and not just a normal value. Void A(DateTime?

P=null) { } Another alternative is: void A(DateTime p=default(DateTime)) { } Which shows that a default parameter can use default(T) as valid default parameter value for user defined types. Or just overload the method for the different number of parameters.

Thanks :) – Alex Jul 28 at 10:06 You could try using readonly if you're looking to ensure that the value doesn't change. And I believe this can be used in conjunction with nullable type?. – eternalmatt Jul 28 at 14:47 @eternalmatt I don't follow - how does this help having an optional DateTime parameter?

If it's optional it'll need a default value, and since I can't provide a compile-time constant it seems CodeInChaos' solution is best. – Alex Jul 28 at 17:00.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions