从国名或RegionInfo对象获取CultureInfo对象 [英] Get CultureInfo object from country name or RegionInfo object

查看:252
本文介绍了从国名或RegionInfo对象获取CultureInfo对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

,例如CH,我怎么能得到一个CultureInfo对象?特定国家code是动态的(在运行时更改)。
我只有全国code,我想知道是否有可能创建的只是全国code CultureInfo对象。不要紧,我得到它的确切文化(FR-CH / DE-CH)。

Given a specific country code, e.g. "CH", how can I get a CultureInfo object? The specific country code is dynamic (changes at runtime). I only have the country code, and i want to know if it is possible to create a CultureInfo object from just the country code. It doesn't matter which exact culture I get (fr-CH/de-CH).

我试图做这样的事情:

CultureInfo c = CultureInfo.CreateSpecificCulture("CH");

将有可能从一个RegionInfo对象创造一种文化?
然后,它是这样的:

Would it be possible to create a culture from a RegionInfo object? Then it would look like this:

RegionInfo r= new RegionInfo("CH");
CultureInfo c = CultureInfo.CreateSpecificCulture(r);

显然,preceding例子不编,他们只是给出我想要实现的想法。

Obviously the preceding examples don't compile, they just give an idea of what I'm trying to achieve.

推荐答案

如果你只有全国code,你可以使用这样的事情来获得与该国有关的所有相关信息文化:

If you only have the country code, you could use something like this to get all culture infos associated with that country:

var cultureInfos = CultureInfo.GetCultures(CultureTypes.AllCultures)
                              .Where(c => c.Name.EndsWith("CH"));

这篇关于从国名或RegionInfo对象获取CultureInfo对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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