There is a debate between my team members about the declaration of a Constants class. We are moving the constant variables into a separate class like below.

public class Constants
      public const string StateId = "ST";
      public const string CountryId = "CI";

A few of my team members suggested that we declare the class as sealed to avoid overriding option, and a few are suggesting that we mark it as static to avoid instance creation of the Constant class.
However, I prefer to have it as Sealed with a static constructor, since it will help us to initialize the read-only variables in future need. Please give us some advice on this.

  • Whichever what you go, one consideration could be to use an interface in the system rather than the constants class itself to avoid dependencies between the objects and a "Global" type class???
    – dreza
    Commented Feb 26, 2014 at 6:27
  • So you agree on making the class static and just asking if you should add a static constructor now or later? I don't see any opposing opinions in your question, please clarify.
    – Doc Brown
    Commented Feb 26, 2014 at 7:15
  • 3
    recommended reading: Why is asking a question on “best practice” a bad thing?
    – gnat
    Commented Feb 26, 2014 at 7:20
  • 2
    I don't get your question. If a class has no instance members, you can mark it static. This is completely orthogonal to the presence or absence of a static constructor. Commented Feb 26, 2014 at 12:46
  • 1
    Are your constants actually constants in the mathematical sense, or is this a form of configuration? Commented Feb 26, 2014 at 12:47

1 Answer 1


It's not totally clear what your question is, but if the values are truly constant, I don't see a problem with the simple option of:

    public static class LocationConstants
        public const string StateId = "ST";
        public const string CountryId = "CI";

Using static in the class declaration signals your intention for the purpose of this class.

Marc Gravell describes some of the potential issues with constants in this Stack Overflow answer. Only you will know if these are a problem in your codebase, but if the values could ever change, use public static readonly instead of const, else any code referring to the constants will need to be rebuilt if the values change.

  • 1
    One of the caveats you can find using const variables is clearly explained here. Since codebases tend to grow and get more complex, it is better to avoid using const, the performance gain is usually not worth the risks of potential trouble in the future, IMHO. I prefer to use public static readonly variables for constants.
    – joanlofe
    Commented Mar 7, 2019 at 15:07
  • @joanlofe, what do you mean by "variables for constants"? aren't the terms "variable" and "constant" mutually exclusive?
    – jarmanso7
    Commented Apr 27, 2021 at 8:56
  • 1
    @jarmanso7 I realize that phrase does not convey well what I wanted to say. It should be rewritten as "I prefer to use public static readonly for constants", but I cannot edit my comment.
    – joanlofe
    Commented Apr 27, 2021 at 14:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.