2
  1. Should I use a .resx file or a static class to store my strings?
  2. What are the pros and cons for each?

I know that using a .resx means you don't need to compile the project every time you change a string, but are there any other pros/cons?

Shweta Pathak
  • 775
  • 1
  • 5
  • 21
David Klempfner
  • 8,700
  • 20
  • 73
  • 153
  • 2
    Possible duplicate of [Resource File vs Static Class for values that will not need to be localized in C#](http://stackoverflow.com/questions/5655880/resource-file-vs-static-class-for-values-that-will-not-need-to-be-localized-in-c) – Nikhil Vartak Oct 16 '15 at 04:39
  • A localization service can very easily localize the strings in a .resx file. You just send out your .resx file and you get other ones back so your program can now speak, say, Chinese. They neither can, nor want to, change your source code. If you don't think it matters now then keep in mind that it may well matter a couple of years from now. Your boss surely likes the idea of having another 5 billion potential customers. – Hans Passant Oct 16 '15 at 07:37

1 Answers1

1

Another point can be come to your mind while using resource file is

Will a resource file work properly for large amounts data?

I think the limitation is the file-size limitation of the operating system and that is 4 GB on 32 Bit systems, if I remember correctly. For 64 bit it should be even bigger. Anyway, for the purpose to store the static text, it should be more than enough.

Thus, in my opinion, this should not be done anywhere else if the text will be static.

An alternative approach would be creating a class to control access to your resource files. This class might be used to store the keys to access your resource files and a have strongly typed way to retrieve available resources of the project.

Some references on SE answers on resources:

Resource string location

Using .resx files for global application messages

References from MSDN :

Resource Files (Visual Studio)

Community
  • 1
  • 1
Krsna Kishore
  • 8,233
  • 4
  • 32
  • 48