asp.net - How to get the country code from a specific country in c#? -
i've country dropdownlist want selected countries country code. user select "the netherlands" want country code "nl" don't know how this. using c# server coding.
can me please.
thanks in advance.
actually question how convert english name iso 3166-2 code. "united state" "us" using regioninfo.
you can write linq dictionary of <name,code>
var countries = cultureinfo.getcultures(culturetypes.specificcultures) .select(x => new regioninfo(x.lcid)) .select(x => new[] { new { name = x.displayname, code = x.name }, new { name = x.nativename, code = x.name } }) .selectmany(x => x) .distinct() .todictionary(x => x.name, x => x.code, stringcomparer.invariantcultureignorecase);
now can use as
console.writeline(countries["united states"]);
Comments
Post a Comment