Get CultureInfo object from country name or RegionInfo object

前端 未结 3 1200
面向向阳花
面向向阳花 2020-12-16 14:43

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

3条回答
  •  情深已故
    2020-12-16 14:58

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

提交回复
热议问题