Search code examples
asp.net.netglobalization

GetCountries from .NET not delivering all countries?


When I use the following code (which used to work fine) I now get, with .NET 4.6, a list that does not include Namibia and includes Yabuuti about 50 times before filtering. Any idea why or what has changed?

    private void SetCountriesComboBox()
    {
        RegionInfo country = new RegionInfo(new CultureInfo("en-US", false).LCID);
        List countryNames = new List();
        foreach (CultureInfo cul in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
        {
            country = new RegionInfo(new CultureInfo(cul.Name, false).LCID);
            countryNames.Add(country.DisplayName.ToString());
        }
        IEnumerable nameAdded = countryNames.OrderBy(names => names).Distinct();
        foreach (string item in nameAdded)
        {
            comboBox1.Items.Add(item);
        }
    }

Solution

  • RegionInfo returns information on cultures, not countries. There is no inbuilt method to return countries (as they have the ability to change infrequently)