Converting country codes in .NET

前端 未结 10 1726
难免孤独
难免孤独 2020-12-04 23:55

In .NET is there any way to convert from three letter country codes (defined in ISO 3166-1 alpha-3) to two letter language codes (defined in ISO 3166-1 alpha-2) eg. convert

10条回答
  •  没有蜡笔的小新
    2020-12-05 00:42

    The RegionInfo class does know the three-letter code (in the ThreeLetterISORegionName property), but I don’t think there is a way to get RegionInfo based on this code, you would need to enumerate all regions and add them to your own dictionary, with the three-letter code as a key.

    However, I think the .NET Framework uses RegionInfo to work with cultures, not countries in the ISO 3166-1 sense. Therefore, many countries from the ISO 3166-1 standard are not available (try e.g. SX). I guess you should create your own country codebook.

    Edit: From 246 countries in my current country codebook, RegionInfo is available for 125 of them, the rest (121) are not supported. Conclusion: This is not a good way to get a country codebook.

提交回复
热议问题