获取一个字符串动态地从字符串资源 [英] Getting a string dynamically from strings resources
问题描述
我工作的一个本地化的C#.NET应用程序,我们使用的是 strings.resx
文件翻译应用程序中的硬codeD字符串。我用下面的code提取它们:
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");
我一直在玩弄一个小与的ResourceManager
,但我不能找到一种方法,直接到我的 strings.resx
文件。
I have been toying a little with the ResourceManager
, but i can't find a way to direct it to my strings.resx
file.
我该怎么办呢?
推荐答案
一个小的搜索做的伎俩。我有权利的ResourceManager
可在我的字符串
类:
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");
这篇关于获取一个字符串动态地从字符串资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!