c#使用资源文件完成国际化

路径结构如下

namespace UnitTestProject1
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            //UnitTestProject1.ZH为资源文件的完整名称,此处为namespace+name,后续通过配置文件,动态加载不同的文件即可完成国际化的任务
            ResourceManager resManagerA = new ResourceManager("UnitTestProject1.ZH", typeof(UnitTest1).Assembly);
            string astring = resManagerA.GetString("Test1");
            Console.WriteLine(astring);

       //资源文件中的数据添加完成后会自动生成static类型的值,如果只是使用值,可以直接调用
//var str = ZH.Test1; //System.Console.WriteLine(str); } } }

猜你喜欢

转载自www.cnblogs.com/ives/p/resx.html