Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# : Get country name from country code

Tags:

c#

cultureinfo

I am trying using c# to get the country name from a country code

For example :

  • fr-fr gets me France
  • it-it gets me Italy

The problem with my code is that I am not getting the name but a information like this :

French (France)

This is my code :

var cultureInfo = new CultureInfo("fr-fr");
var result : cultureInfo.EnglishName

My result is "French (France)" instead of France.

I have managed to get what I want by use the parent property of the cultureInfo but I am not sure if it's a good method.

like image 634
user2443476 Avatar asked Apr 24 '16 09:04

user2443476


2 Answers

Because CultureInfo.EnglishName still returns culture name.

You can create a RegionInfo based on this culture and call it's EnglishName property as well.

var cultureInfo = new CultureInfo("fr-fr");
var ri = new RegionInfo(cultureInfo.Name);
ri.EnglishName // France

or

var cultureInfo = new CultureInfo("it-it");
var ri = new RegionInfo(cultureInfo.Name);
ri.EnglishName // Italy
like image 68
Soner Gönül Avatar answered Sep 28 '22 01:09

Soner Gönül


You can get country name this way

RegionInfo cultureInfo = new RegionInfo("fr-fr");
string result = cultureInfo.EnglishName;
like image 21
Mostafiz Avatar answered Sep 27 '22 23:09

Mostafiz