遇到需要根据代码提供的密钥访问存储在资源文件中的字符串值的情况.
我怎样才能做到这一点?
注意:资源文件存在于我的解决方案中的Web项目中,我想从我的silverlight应用程序访问它.
Zbi*_*iew 18
您可以使用ResourceManager类:
ResourceManager myManager = new ResourceManager(typeof(MyResource));
string myString = myManager.GetString("StringKey");
Run Code Online (Sandbox Code Playgroud)
假设你的资源文件名是“Resource.resx”,然后你想动态传递key,
using System.Resources;
string resVal = Resource.ResourceManager.GetString(dynamicKeyVal);
Run Code Online (Sandbox Code Playgroud)
如果它不起作用,请告诉我,我会处理它并提供适当的解决方案。
| 归档时间: |
|
| 查看次数: |
23094 次 |
| 最近记录: |