All applications always use some constant values.
I don’t like hard-coded these values in my application in every code, as it significantly reduces maintainability.
I have 2 options:
or
- Create a resource file (.resx) and save my constant values and formulas there.
In my application, I used the second approach. One of the problems that I encountered when using the resource file was that I could not use the optional parameter with them.
eg. below does not work:
public void DoSomething(string id = Resources.Constants.Id) {
The error was that the Id value was not determined at run time.
Basically, how would you use and recommend managing your constants for each class? why?
My current approach is that if I have constants that should only be used inside one class, I create a class of static constants in the class. If my constants will be used in several classes or projects, I will put them in a resource file, for example. PageUrls.resx.
Thanks,
source share