在. net中,系统中有CultureInfo类。全球化的名称空间。它有两个相似的属性,都返回CultureInfo类型的值:CurrentCulture和currentuicculture。

它们之间的区别是什么?

什么时候用,为什么用?


CurrentCulture是系统默认用户语言环境的. net表示。它控制默认的数字和日期格式等。

CurrentUICulture指的是Windows 2000中引入的默认用户界面语言。这主要是关于应用的UI本地化/翻译部分。

无论系统配置为什么区域选项,都将是. net应用程序中的“Current”值。

通常它们都是一样的。但在我的系统上,它们会有所不同:我更喜欢使用德语格式的数字和日期,因此CurrentCulture将是德语格式,但我也更喜欢所有应用程序都使用英语,因此CurrentUICulture将是英语格式。

有一篇很好的文章是关于这个主题的:整理:为什么我们同时拥有当前文化和当前文化

这是我用来记住使用哪个的简单技巧:

(date, currency, double).tostring = CurrentCulture

resource.fr-CA.resx file = currentUICulture

差异:

CurrentCulture用于日期和货币格式化,而currentuicculture用于语言/翻译。它将被ResourceManager用于按区域性查找资源。 “CurrentCulture”类的命名空间在“System”中。全球化而currentuicculture来自System.Threading。 CurrentCulture在会话中的不同请求之间持久化,而currentuicculture需要为每个请求设置。

相似:

它们都是System.Globalization.CultureInfo实例。

除了其他用户的解释之外,还有一个很好的方法可以让你有所不同,这也是web应用程序开发中的一个重要方面:

CurrentCulture represents the setup of the web server. For example, if your ASP.NET web application is hosted in Germany, the value of CutlureInfo.CurrentCulture would most probably be de-DE. Thus, the default .ToString() formatting for IFormattable types would use the default German formattings, or the ones which have been set up on the server OS as defaults. CurrentUICulture can be captured from the user agent, and may represent the user interface culture of the client connecting to the website. For example, if you load that website from Russia, your local settings are set to use Russian language, and your user agent sends your locale settings to the server (Opera and IE do this automatically, not sure for Chrome and FireFox), the CurrenUICulture would represent ru-RU. This will cause any resources like localized strings retrieved via ResourceManager or localization expressions in ASP.NET aspx/ascx files to be in Russian (if translations are available).

值得注意的是,CurrentUICulture支持非特定国家的语言环境,如“en”(中性文化),而CurrentCulture只支持特定国家的语言环境,如“en- gb”。将CurrentCulture设置为中性区域性将引发ArgumentException。

我认为这是因为日期和货币等格式与国家本身的联系更紧密,但所显示的语言通常在国家之间是可以互换的。