Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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).

I'm trying do something like this:

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

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);

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
896 views
Welcome To Ask or Share your Answers For Others

1 Answer

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"));

EDIT: adding - before CH to prevent an edge case, as pointed out by @JeppeStigNielsen (see comments below).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...