using resource files with parameters

三世轮回 提交于 2019-12-24 03:35:21

问题


My question is about resource files (.resx) in c#.(the "strings" part) I'm using it to store my messages,and I want to know how can we use the "value" of a resource entry with parameters ?!

example :

Name : ShowCellValue Value : value on cell : ? and row : ? is : ?

and I want to fill the "?" parameters with different values.

Thank you,


回答1:


You can use string.Format on strings stored in your resource files.

Store ShowCellValue as

string showCellValue = "value on cell {0} and row {1} is {2}";

Then when you want to use it, just use the ResourceManager:

ResourceManager rm = new ResourceManager("resource root name", 
    Assembly.GetExecutingAssembly());
MessageBox.Show(string.Format(rm.GetString("showCellValue"), 
    cellName, rowName, cellValue);


来源:https://stackoverflow.com/questions/3537159/using-resource-files-with-parameters

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!