当使用CultureInfo.GetCultureInfo(字符串)或CultureInfo.CreateSpecificCulture(字符串) [英] When to use CultureInfo.GetCultureInfo(String) or CultureInfo.CreateSpecificCulture(String)

查看:1719
本文介绍了当使用CultureInfo.GetCultureInfo(字符串)或CultureInfo.CreateSpecificCulture(字符串)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我应该叫的CultureInfo。<一个href="http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.createspecificculture.aspx">CreateSpecificCulture(String)而随后的CultureInfo。<一个href="http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.getcultureinfo.aspx">GetCultureInfo(String). MSDN文档也不是很清楚。

When should I call CultureInfo.CreateSpecificCulture(String) rather then CultureInfo.GetCultureInfo(String). The MSDN documentation is not very clear.

也就是有没有办法更便宜的检查,如果一种文化的名称是有效的?

Also is there a way to cheaper check if the name of a culture is valid?

我的认为的,如果你通过恩而不是EN-GB为CultureInfo.CreateSpecificCulture(字符串),你会得到一个错误,但CultureInfo.GetCultureInfo(字符串)不介意。例如。 CultureInfo.GetCultureInfo(字符串)可以应付,如果你只是传递语言。 不过,我仍不清楚这一点。

I think if you pass "en" rather then "en-GB" to CultureInfo.CreateSpecificCulture(String) you will get an error, but that CultureInfo.GetCultureInfo(String) does not mind. E.g. CultureInfo.GetCultureInfo(String) can cope if you only pass an language. However I am still unclear on this.

推荐答案

这取决于一点上你所需要的培养。短名称(EN,FR等)用于中性文化,足以满足特定语言资源管理。但对于数字和日期格式,你需要一个特定的文化,像EN-GB。

It depends a bit on what you need the culture for. The short names ("en", "fr" etc) are used for neutral cultures, sufficient for language specific resource management. But for numerical and date formatting you need a specific culture, like "en-GB".

CultureInfo.CreateSpecificCulture(EN); 正常工作在这里。它特别为了得到'A'特定的培养是中性的。

And CultureInfo.CreateSpecificCulture("en"); works fine over here. It is especially intended to get 'a' specific culture for a neutral one.

这篇关于当使用CultureInfo.GetCultureInfo(字符串)或CultureInfo.CreateSpecificCulture(字符串)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆