Get RegionInfo by country name?

前端 未结 6 1637
一个人的身影
一个人的身影 2020-12-18 22:52

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

new RegionInfo(\"United Kingdom\");

but this throws an exception a

6条回答
  •  不思量自难忘°
    2020-12-18 23:18

    That same page you linked also says:

    The RegionInfo name is one of the two-letter codes defined in ISO 3166 for country/region. Case is not significant; however, the Name, the TwoLetterISORegionName, and the ThreeLetterISORegionName properties return the appropriate code in uppercase.

    The codes are on the page, and GB appears to be the 2 letter code for the UK (it's in code order to be difficult searching!). So try this:

    new RegionInfo("GB");
    

    Or if you're using .NET 2.0+, it's recommended you use the full culture name:

    new RegionInfo("en-GB");
    

提交回复
热议问题