3

I've never used string resources before so I would like to ask, when should I use them and why are they beneficial when I can just define a string?

3 Answers 3

11

The reason for using string resources is so that UI designers can modify them easily. If you define it in code, the designer would have to edit code, whereas if you define it in a resource, the resource file can be edited, and your application doesn't have to be rebuild. Having a separate resource file also helps in project management - all strings that ever appear to a user are at a central place and product management can revise them as necessary. Does that make sense?

3
  • so when should i, if ever, hardcode a string into my program?
    – Marlon
    Commented Feb 18, 2010 at 1:15
  • 3
    @Marlon - you can hardcode a string provided it's not being displayed to the end user. Commented Feb 18, 2010 at 1:20
  • 2
    @Marlon: you hardcode strings that never show up in your user interface. filenames, database key names, etc. Commented Feb 18, 2010 at 1:21
7

In a word: internationalization. Strings in resource files greatly ease the pain of providing user messages in multiple languages.

1

One benefit of string resources is that they exist in a separate file and you can edit them separately from the code and/or load different versions for different languages.

The separate editing can be done by a non programmer - especially useful if they translating,

Not the answer you're looking for? Browse other questions tagged or ask your own question.