区域
线程默认区域为当前计算机所选区域
设置当前区域:
Thread.CurrentThread.CurrentCulture = new CultureInfo(“zh-cn”);
获取当前区域:
Console.WriteLine(Thread.CurrentThread.CurrentCulture.ToString());
区域名称:
“zh-cn” 中文
“en-us” 英文
资源
1.新建资源文件
资源名+区域名+”.resx”
如:Test.zh-CN.resx
提示:“.” 表示层级结构,如建文件夹后,需要wenjianjiaming.XXX.resx
2.添加资源
3.获取资源
ResourceManager rm = new ResourceManager(“ResourceTest.Test”, Assembly.GetExecutingAssembly());
Console.WriteLine(rm.GetString(“HolleWrole”));
示例资源文件:
示例代码:
static void Main(string[] args)
{// ResourceTest.Test = 资源命名空间.资源名ResourceManager rm = new ResourceManager("ResourceTest.Test", Assembly.GetExecutingAssembly()); ;// 根据当前默认区域获取资源字符串Console.WriteLine(rm.GetString("HolleWrole"));// 获取区域为"zh-cn"的资源字符串Console.WriteLine(rm.GetString("HolleWrole", new CultureInfo("zh-cn")));// 获取区域为"en-us"的资源字符串Console.WriteLine(rm.GetString("HolleWrole", new CultureInfo("en-us")));// 获取资源中的图片using (Image logo = (Image)rm.GetObject("image1")){logo.Save("logo.jpg");}Console.ReadKey();
}
链接:https://blog.csdn.net/dabusidede/article/details/108466338