C#2.0的当前区域设置

时间:2014-06-02 03:54:00

标签: c#-2.0

如何将其转换为C#2.0(不使用lambda表达式)?

How to get current regional settings in C#?

class Program
{
    private class State
    {
        public CultureInfo Result { get; set; }
    }

    static void Main(string[] args)
    {
        Thread.CurrentThread.CurrentCulture.ClearCachedData();
        var thread = new Thread(
            s => ((State)s).Result = Thread.CurrentThread.CurrentCulture);
        var state = new State();
        thread.Start(state);
        thread.Join();
        var culture = state.Result;
        // Do something with the culture
    }
}

1 个答案:

答案 0 :(得分:0)

使用Anonymous Method

    class Program
    {
        private class State
        {
            public CultureInfo Result { get; set; }
        }

        static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture.ClearCachedData();
            Thread thread = new Thread(delegate(object s)
            {
                ((State) s).Result = Thread.CurrentThread.CurrentCulture;
            });
            State state = new State();
            thread.Start(state);
            thread.Join();
            CultureInfo culture = state.Result;
            // Do something with the culture
        }
    }