I want to retrieve all country codes (like +61 for Australia) by giving country name. Is there built in method for retrieving country code in c# like
int countryCode = CultureInfo.getCountryCode("CountryName");
I saw some methods on internet but non of them is simple. I want simple method for retrieving country code by giving country name. I saw Google libphonenumber but is there any simple solution because I am having trouble while including thi library because I am using visual studio 2015 but this library is build in visual studio 2017. If this library is only the solution then how can I include this library in my visual studio 2015 project?
This is the code for getting all countries
public static List<string> countryList()
{
List<string> cultureList = new List<string>();
CultureInfo[] info = getCultureInfo();
foreach (CultureInfo culture in info)
{
RegionInfo region = new RegionInfo(culture.LCID);
if (!(cultureList.Contains(region.EnglishName)))
{
cultureList.Add(region.EnglishName);
}
}
cultureList.Sort();
return cultureList;
}
Now, how can I get country codes all of theses?
To answer your question, if you are talking about telephone prefix as country code, then there is no builtin way as I am aware of. Neither, culture nor region contains that information.
The easiest way is to take advantage of some free API, for example geognos , where you can get the json data of a country using the code you can get from culture/region. For example data for Australia would be found using the AU-code .
Edit.
To clarify my answer a bit, country code has nothing to do with tel. prefix and country codes at different formats can be fetched from culture/region information.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.