89

What compelling reasons exist for using them?

2
  • 11
    If you've never used a resx file before, but have your own string tables and the like (or worse, strings scattered throughout the code, all locally defined) and haven't seen a reason to change that approach, then this is a legit question.
    – mmr
    Jul 15, 2009 at 21:03
  • 12
    I've never used resx before. That is the reason behind the question.
    – Newbie
    Jul 16, 2009 at 14:50

5 Answers 5

96
  • Resource files give you an easy way to localize/internationalize your .net applications by automatically determining which language resx file to use based on the user's locale. To add more languages, simply add another translated resource file.

  • Resource files give you a central location to store your strings, files and scripts and refer to them in a strongly-typed manner (so the compile will break if you reference them improperly).

  • Resource files can be compiled into satellite assemblies, making it easy to change up the resources in a production application without having to recompile the whole thing.

0
34

As a supplement to the other answers, string resources are for human-readable text, not constants that will be used programmatically. They're great for error messages, button labels and the like.

Very often, rather than the final string, we store a format string so that variables can be substituted in at the last moment. The nice thing about this method is that, unlike concatenation, it's not broken when a language has different word order requirements.

2
  • 1
    +1 for that indeed! Though There Be Dragons still; e.g. where English has "one" and "many", Slovenian e.g. has "one", "few" and "many".
    – Cornelius
    Jan 15, 2016 at 12:36
  • 1
    It's an annoying redirection to a separate "res" file ever time someone references a formatted string for logging.
    – Jmoney38
    Feb 15, 2017 at 16:31
14

Resource files enable you to change the text/graphics your program will display without editting the code of the program itself. For many reasons, it is often considered ideal to avoid needing to edit your program's source code in order to make changes that are not part of your application's logic.

13

With resx you can have one per language (that is spoken language not programming language) enabling your program / system to be multilingual.

3
  • 15
    Yes - the world is NOT just speaking English!
    – marc_s
    Jul 15, 2009 at 21:06
  • any tutorial on how to do that with a simple example? Feb 6, 2018 at 5:06
  • @KansaiRobot hope you find this blog helpful - Satellite Assemblies in .NET
    – RBT
    Jan 25, 2022 at 4:41
4

In addition to the answers above, resource files can also provide you an place to store test files for performing Read/Write tests. That way, regardless of how other people's environment is set up, you can have a place to store logs or other files.

Keep in mind that what files you do place in resources must be serializable. Check below for more info:

https://msdn.microsoft.com/en-us/library/f45fce5x(v=vs.80).aspx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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