Avoiding Hard Coding Strings

This is a question regarding best coding techniques. I would like to know the consensus on how to best avoid strings and hardcoding values ​​in a .NET application. What I have seen so far, where I previously worked:

  • Using .resx Resources
  • storing these values ​​and lines in App.config or web.config
  • creating a static ApplicationStrings class and declaring all strings and values ​​there:

    public static class ApplicationStrings
    {
        #region constants
        public const string APPLICATION_NAME = "X";
        public const string APPLICATION_RESOURCEMANAGER_NAME = "ResourceManagerX";
        public const string APPLICATION_DEFAULT_LOGFILENAME = "log.txt";
    }
    

However, this is not the third way, just another hard code? Does it make sense to have such a class? The benefit would be that all lines are in one place, but does that really exclude hardcode?

Also, if you have developed other habits for this situation, feel free to post.

+5
4

, , , . , , , , . , .

i18n l10n. , .

+4

, , .

+1

, ApplicationSettings , (i) (ii), , . , , .config.resx

+1
source

Well, I think ApplicationStrings is a good solution.

0
source

All Articles