Search code examples
c#globalization

How to get the country code from CultureInfo?


I have the following:

System.Globalization.CultureInfo c = new System.Globalization.CultureInfo("en-GB");

var a = c.DisplayName;
var b = c.EnglishName;
var d = c.LCID;
var e = c.Name;
var f = c.NativeName;
var g = c.TextInfo;
var h = c.ThreeLetterISOLanguageName;
var i = c.ThreeLetterWindowsLanguageName;
var j = c.TwoLetterISOLanguageName;

None of this gives me the country code, e.g. GB.

Is there a way to get it without string splitting?


Solution

  • var c = new CultureInfo("en-GB");
    var r = new RegionInfo(c.LCID);
    string name = r.Name;
    

    Most probably you need to use r.TwoLetterISORegionName property.

    string regionName = r.TwoLetterISORegionName;