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

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -