Take the 2-minute tour ×

I am working on a localised C#.NET application and we are using a strings.resx file to translate hardcoded strings in the application. I use the following code to extract them:

using MyNamespace.Resources


string someString = strings.someString;

But, now I want to be able to define the name of the string in the call, something like this:

string someString = GetString("someString");

I have been toying a little with the ResourceManager, but i can't find a way to direct it to my strings.resx file.

How do I do that?

share|improve this question

2 Answers 2

ResourceManager.GetString should do.

Stripped down example from MSDN:

ResourceManager rm = new ResourceManager("RootResourceName",
string someString = rm.GetString("someString");
share|improve this answer
Yes, I found that, but now idea how I should instantiate my ResourceManager. I got it working with ResourceManager rm = strings.ResourceManager;. No need to instantiatie: it's already there. –  Bart Friederichs Nov 2 '12 at 11:35
@Bart: Did you try the constructor with assembly? –  Vlad Nov 2 '12 at 11:36
@Bart: Well, if you already have the needed one, it's nice. –  Vlad Nov 2 '12 at 11:37
yes, but I didn't know what "RootResourceName" or SomeClass should be. The strings.ResourceManager is way easier. –  Bart Friederichs Nov 2 '12 at 11:38
@Bart: class is needed only in order to get to the assembly. You could perhaps use just Assembly.GetCurrentAssembly or like that. And RootResourceName is, according to the docs, "The root name of the resource file without its extension but including any fully qualified namespace name. For example, the root name for the resource file named MyApplication.MyResource.en-US.resources is MyApplication.MyResource." However, if the resource manager is already available, it's better to take it as is. –  Vlad Nov 2 '12 at 11:41
up vote 4 down vote accepted

A little searching did the trick. I have the right ResourceManager available in my strings class:

ResourceManager rm = strings.ResourceManager;
string someString = rm.GetString("someString");
share|improve this answer

Your Answer


