本文介绍了国家代码 - C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有一个字符串,我需要验证,如果它是一个国家代码。文化是德国人。有没有办法,我可以打电话来获得在德国文化国家代码列表,而不必键入出所有的274(?)规范自己的方法?I have a string which I need to verify if it's a Country code. The culture is German. Is there any method that I can call to get a list of Country codes in a German culture without having to type out all the 274 (?) codes myself?谢谢, Teja公司。Thanks,Teja.推荐答案当你说国家代码我想你指的是两个字母的代码作为 ISO 3166 。然后你可以使用RegionInfo构造函数来检查,如果你的字符串是一个正确的代码When you say "country code" I assume you mean the two-letter code as in ISO 3166. Then you can use the RegionInfo constructor to check if your string is a correct code.string countryCode = "de";try { RegionInfo info = new RegionInfo(countryCode);}catch (ArgumentException argEx){ // The code was not a valid country code}您也可以,因为你在你的问题的状态,检查它是否是为德语有效的国家代码。然后你只是通过在特定的文化名连同国家代码You could also, as you state in your question, check if it is a valid country code for the german language. Then you just pass in a specific culture name together with the country code.string language = "de";string countryCode = "de";try { RegionInfo info = new RegionInfo(string.Format("{0}-{1}", language, countryCode));}catch (ArgumentException argEx){ // The code was not a valid country code for the specified language} 这篇关于国家代码 - C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-05 16:07