以编程方式访问资源文件中的值

Roh*_*aan 9 c# asp.net

遇到需要根据代码提供的密钥访问存储在资源文件中的字符串值的情况.

我怎样才能做到这一点?

注意:资源文件存在于我的解决方案中的Web项目中,我想从我的silverlight应用程序访问它.

Zbi*_*iew 18

您可以使用ResourceManager类:

ResourceManager myManager = new ResourceManager(typeof(MyResource));
string myString = myManager.GetString("StringKey");
Run Code Online (Sandbox Code Playgroud)


Ksh*_*gra 7

假设你的资源文件名是“Resource.resx”,然后你想动态传递key,

using System.Resources;
string resVal = Resource.ResourceManager.GetString(dynamicKeyVal);
Run Code Online (Sandbox Code Playgroud)

如果它不起作用,请告诉我,我会处理它并提供适当的解决方案。


Mon*_*kar 5

我通常这样访问资源

Resources.MyLocalised.CompanyName;
Run Code Online (Sandbox Code Playgroud)