Alon1980
Alon1980

Reputation: 1267

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!

Upvotes: 8

Views: 4405

Answers (3)

tvanfosson
tvanfosson

Reputation: 532435

I would typically store these as application Settings or Resources.

Upvotes: 2

vcsjones
vcsjones

Reputation: 141598

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.

Upvotes: 5

anivas
anivas

Reputation: 6547

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

Upvotes: 6

Related Questions