按国家名称获取RegionInfo? [英] Get RegionInfo by country name?
问题描述
我希望能够通过执行以下操作来获得 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屋!