Constant DateTime in C#

As some of the earlier responses note, a const DateTime is not natively supported in C# and can’t be used as an attribute parameter. Nevertheless, a readonly DateTime (which is recommended over const in Effective C#, 2nd edition [Item 2]) is a simple workaround for other situations as follows:

public class MyClass
{
    public static readonly DateTime DefaultDate = new DateTime(1900,1,1);
}

Leave a Comment