How to get country name

xscape picture xscape · Sep 7, 2010 · Viewed 19.6k times · Source

I used the code below to get the list of culture type, is there a way on how to get just the country name?

Thank you

static void Main(string[] args)
{
    StringBuilder sb = new StringBuilder();
    foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
    {
        sb.Append(ci.DisplayName);
        sb.AppendLine();
    }
    Console.WriteLine(sb.ToString());
    Console.ReadLine();
}

Sample Output:

Spanish (Puerto Rico)

Spanish (United States)

Answer

Eric MSFT picture Eric MSFT · Sep 9, 2010

You can use the Name property of the CultureInfo to construct a RegionInfo. You can then use the DisplayName property. Try:

foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
{
    var ri = new RegionInfo(ci.Name);
    Console.WriteLine(ri.DisplayName);
}