I have seen these two approaches for constant declaration which are to be used in the project.
-
Constants in a public module.
-
Constants in a NonInheritable(Sealed) class
Does anybody uses any other approach for the constant declartion ?
Is there any difference between these approaches, any pros and cons ?
Thanks.
Put the constant in the class where it’s most relevant – e.g.
Math.Pi,Int32.MinValueetc.I’ve seen various constants which should actually be enums, too – particularly for status codes etc.
I don’t think it’s wise to create a class (or module) just for constants unless there really is no sensible class that those constants are associated with.