1

I just downloaded ReSharper, because many of my coworkers have been fawning over it for ages. I was looking through one of my programs, and I found a bunch of suggestions made by the extension, some helpful, some not. One suggestion, however, really confused me. Originally, I had this simple code:

foreach (Device foo in MasterDataGrid.ItemsSource)
{
     Console.WriteLine("Value for {0}: {1}", foo.Name, foo.OriginalValue);
}

This works perfectly fine, and I have been formatting strings like this for ages now with no issue. However, ReSharper suggested that I use a resource instead of a string literal. Here is the code once ReSharper was done with it.

foreach (Device foo in MasterDataGrid.ItemsSource)
{
     Console.WriteLine(Properties.Resources.MainWindow_HistoryButton_Click_Value_for__0____1_, foo.Name, foo.OriginalValue);
}

I am a novice to C# and programming in general, so I had no idea that this was a thing one could do.

Is this in any way better than what I had? In what situations would I notice a difference between the two pieces of code, and how big of a difference does it make?

Cubemaster
  • 507
  • 1
  • 6
  • 20

1 Answers1

3

It is necessary if you are going to ship your application in different languages. the translators can then localize the resource file only, you have all strings in one place, and translators need not know which of the string literals in your code are meant to be translated, and cannot mess up the code while translating.

Cee McSharpface
  • 8,493
  • 3
  • 36
  • 77