ebb
ebb

Reputation: 9377

Hard-coded strings vs Resource file

As the title says then the question is relative simple however I cant decide whether a resource file with strings in is better than hard-coded strings... Whats your opinion?

Thanks in advance

Upvotes: 6

Views: 4247

Answers (3)

citronas
citronas

Reputation: 19365

Have a realistic look at your application.

Reasons for resource files:

  • Do you support multiple languages? If yes, you will use resource files.
  • You are using a mid-size or bigger application and want to use the same Strings all over your web application? => Use resource files and get strong typed access to all your strings application wide

Reasons for hard-coded strings:

  • Are you using a small application that will most likely not grow much more and localization is most certain not going to happen. => Hard-Coded Strings

Upvotes: 3

JonH
JonH

Reputation: 33153

I prefer to use the web config file (so a resource file). Hard-coded strings could be duplicated across your code and are much more difficult to "find and replace". Hence, you are prone to error if you have the same hard coded string across any application be it asp.net, C#, vb.net etc.

If you have a resource file with a central place that stores connection information you will sleep better at night. Your other option is to use some sort of constant and reuse that constant across your pages.

Upvotes: 0

Aliostad
Aliostad

Reputation: 81660

Main advantage is in localisation. Performance wise resources have a little more overhead but really not much of an issue.

If I am not worried at all about localisation then I would use constants (and not hard-coded strings).

Upvotes: 5

Related Questions