Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practice for storing application const strings in the code

In my application (C#) i have lots of const messages which are get printed to the log, presented to the user, etc. This const messages are not suppose to change so there is no point putting them in an external file or DB. My solution is very simple - I am thinking about creating a static class and naming it ConstMessages. This class will simply hold lots of public const string variables which can be accessed from anywhere in the application. Can you please suggest if there anything wrong with that method and if there are better ways? Thanks!

like image 997
Alon1980 Avatar asked Jul 03 '11 15:07

Alon1980


3 Answers

I would use readonly instead of const to get over versioning issues.

like image 112
anivas Avatar answered Nov 17 '22 19:11

anivas


That's usually OK for simple applications - another option is a RESX file if you think there is a possibility the application will ever need to be localized / support more than one language.

like image 23
vcsjones Avatar answered Nov 17 '22 17:11

vcsjones


I would typically store these as application Settings or Resources.

like image 2
tvanfosson Avatar answered Nov 17 '22 19:11

tvanfosson