Culture和UICulture之间的区别是什么?区别、Culture、UICulture

由网友(浅忆i)分享简介:可能有人给我多一点信息,在.NET框架中文化和的UICulture 之间的区别是什么?他们做了什么,以及何时使用什么呢?Could someone give me a bit more information on the difference between Culture and UICulture within...

可能有人给我多一点信息,在.NET框架中文化的UICulture 之间的区别是什么?他们做了什么,以及何时使用什么呢?

Could someone give me a bit more information on the difference between Culture and UICulture within the .NET framework? What they do and when to use what?

推荐答案

文化会影响文化相关的数据(日期,货币,数字等)是presented。下面是一些例子:

Culture affects how culture-dependent data (dates, currencies, numbers and so on) is presented. Here are a few examples:

var date = new DateTime(2000, 1, 2);
var number = 12345.6789;

Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");
Console.WriteLine(date); // 02.01.2000 00:00:00
Console.WriteLine(number.ToString("C")); // 12.345,68 €

Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-CA");
Console.WriteLine(date); // 2000-01-02 00:00:00
Console.WriteLine(number.ToString("C")); // 12 345,68 $

Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Console.WriteLine(date); // 1/2/2000 12:00:00 AM
Console.WriteLine(number.ToString("C")); // $12,345.68

文化也影响用户输入的解析以同样的方式:

Culture also affects parsing of user input in the same way:

const string numberString = "12.345,68";
decimal money;

Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");
money = decimal.Parse(numberString); // OK!

Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
money = decimal.Parse(numberString); // FormatException is thrown, TryParse would return false

谨防案件分析所在的成功的,但结果不是你所期待的那样。

Beware of cases where the parsing succeeds but the result is not what you would expect it to be.

const string numberString = "12.345";
decimal money;

Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");
money = decimal.Parse(numberString); // 12345

Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
money = decimal.Parse(numberString); // 12.345, where the . is a decimal point

的UICulture 影响哪些资源文件(资源郎的的.resx)是要由你的应用程序加载到。

UICulture affects which resource file (Resources.lang.resx) is going to be loaded to by your application.

所以加载德资源(presumably本地化的文本),你会设定的UICulture 德国文化,并展示德国的格式(无任何影响的哪些资源加载),您将设置文化

So to load German resources (presumably localized text) you would set UICulture to the German culture and to display German formatting (without any impact on which resources are loaded) you would set Culture.

阅读全文

相关推荐

最新文章