按国家名称获取RegionInfo? [英] Get RegionInfo by country name?

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

问题描述

我希望能够通过执行以下操作来获得 RegionInfo

 新RegionInfo(联合王国); 



不过,这将引发异常,并说,它无法识别。



在此RegionInfo 页面说如果名称不是一个有效的国家/地区名称抛出一个异常。



然而这个的page 指定由类所使用的预定义区域的列表和包含英国,那么为什么不创建一个新的 RegionInfo 与国名工作?


解决方案

  VAR地区= CultureInfo.GetCultures(CultureTypes.SpecificCultures)。选择(X =>新建RegionInfo(x.LCID)); 
VAR englishRegion = regions.FirstOrDefault(区=> region.EnglishName.Contains(名));

如果你想获得 RegionInfo 由国名,你可以得到一个的IEnumerable< RegionInfo> 然后筛选根据中文名如上。这使您可以填充的东西,如组合框太大的能力。


I want to be able to get RegionInfo by doing the following:

new RegionInfo("United Kingdom");

but this throws an exception and says that it is not recognised.

This page on RegionInfo says that an exception is thrown if 'name is not a valid country/region name'.

And yet this page specifies a list of predefined regions used by the class that and contains United Kingdom, so why doesn't creating a new RegionInfo with country name work?

解决方案

  var regions = CultureInfo.GetCultures(CultureTypes.SpecificCultures).Select(x => new RegionInfo(x.LCID));
  var englishRegion = regions.FirstOrDefault(region => region.EnglishName.Contains(name));

If you want to get RegionInfo by the country name, you could get an IEnumerable<RegionInfo> and then filter based on the EnglishName as above. This gives you the ability to populate things such as comboboxes too.

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

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