日期:2014-05-17  浏览次数:20888 次

请教c#多语言问题
直接上代码
新建一dll工程
代码如下
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace ClassLibrary1
{
    public class Class1
    {
        public delegate void Test();
        public Test test;
        public Class1()
        {
            ThreadPool.QueueUserWorkItem(new WaitCallback(test1));
        }

        private void test1(object sender)
        {
            while (true)
            {
                Thread.Sleep(10000);
                if (test != null)
                    test();
            }
        }

        public void test2()
        {
            if (test != null)
                test();
        }
    }
}


然后建立控制台程序,添加资源文件Localize.resx,添加字符串String1值:测试;在添加英文资源Localize.en.resx添加字符串String1值:Test.
控制台程序代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Resources;

namespace ConsoleApplication1
{
    class Program
    {
        private static ResourceManager m_resourceManager = new ResourceManager("ConsoleApplication1.Localize", System.Reflection.Assembly.GetExecutingAssembly());
        static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("en");
            ClassLibrary1.Class1 c1 = new ClassLibrary1.Class1();
            c1.test = new ClassLibrary1.Class1.Test(test);

            c1.test2();

            Console.ReadLine();
            c1.test2();

            Console.ReadLine();
        }

 &nb