#318 – You Can’t Use the static Modifier On a Constant

Although constants can be treated as static member variables, you cannot include the static keyword when declaring a constant.  A constant is always effectively static, so the static keyword would be redundant.  The compiler will generate an error if you include it.

        // This is ok
        const string Demeanor = "friendly";

        // !! Compiler error - constant cannot be marked static
        static const int TheAnswer = 42;

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

One Response to #318 – You Can’t Use the static Modifier On a Constant

  1. Pingback: #789 – Grouping Constants into Their Own Class | 2,000 Things You Should Know About C#

Leave a comment