What are the benefits of resource(.resx) files?

C#.Netvb.netResx

C# Problem Overview


What compelling reasons exist for using them?

C# Solutions


Solution 1 - C#

  • 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.

Solution 2 - C#

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.

Solution 3 - C#

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.

Solution 4 - C#

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

Solution 5 - C#

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNewbieView Question on Stackoverflow
Solution 1 - C#wompView Answer on Stackoverflow
Solution 2 - C#Steven SuditView Answer on Stackoverflow
Solution 3 - C#BrianView Answer on Stackoverflow
Solution 4 - C#Shiraz BhaijiView Answer on Stackoverflow
Solution 5 - C#CameronView Answer on Stackoverflow