Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
May I know how to get the list of regions using System.globalization namespace.
Posted
Updated 11-Jul-18 17:49pm
v2
Comments
Farhan Ghumra 20-Jun-12 2:56am    
Do you want region or country ?
Sandeep Mewara 20-Jun-12 8:34am    
Not clear.

C#
public class Country
    {
        public string countryCode { get; set; }
        public string countryName { get; set; }
    }

public List<Country> GetCountries()
        {
            //create a new Generic list to hold the country names returned
            List<Country> countryList = new List<Country>();

            CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.SpecificCultures);

            var v = cultures.Where(C => C.LCID != 127 & !C.IsNeutralCulture).Select(C => new { new RegionInfo(C.LCID).EnglishName, new RegionInfo(C.LCID).Name }).ToList();

            countryList = v.GroupBy(C => new { C.EnglishName, C.Name }).Select(C => new Country() { countryCode = C.Key.Name, countryName = C.Key.EnglishName }).OrderBy(C => C.countryName).ToList();

            return countryList;
        }
 
Share this answer
 
Comments
Afzaal Ahmad Zeeshan 12-Jul-18 9:01am    
How does this solution improve on top of the one that is already provided?
Member 11585739 18-Jul-18 22:49pm    
it is the same solution , but just i did it using linq query(if any one want it) with extra column county code .
C++
//Code snippet
/// <summary>
/// method for generating a country list, say for populating
/// a ComboBox, with country options. We return the
/// values in a Generic List<t>
/// </t></summary>
/// <returns></returns>
public static List<string> GetCountryList()
{
    //create a new Generic list to hold the country names returned
    List<string> cultureList = new List<string>();

    //create an array of CultureInfo to hold all the cultures found, these include the users local cluture, and all the
    //cultures installed with the .Net Framework
    CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.NeutralCultures);

    //loop through all the cultures found
    foreach (CultureInfo culture in cultures)
    {
        //pass the current culture's Locale ID (http://msdn.microsoft.com/en-us/library/0h88fahh.aspx)
        //to the RegionInfo contructor to gain access to the information for that culture
        RegionInfo region = new RegionInfo(culture.LCID);

        //make sure out generic list doesnt already
        //contain this country
        if (!(cultureList.Contains(region.EnglishName)))
            //not there so add the EnglishName (http://msdn.microsoft.com/en-us/library/system.globalization.regioninfo.englishname.aspx)
            //value to our generic list
            cultureList.Add(region.EnglishName);
    }
    return cultureList;
}

//Example usage
foreach(string country in GetCountryList())
{
    comboBox1.Items.Add(country);
}</string></string></string>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900