Willcode4cash icon

Country list

Willcode4cash | PRO | 08/15/16 03:59:43 AM UTC | 0 ⭐ | 278 👁️ | Never ⏰ | []
C# |

950 B

|

None

|

0 👍

/

0 👎

namespace Sandbox
{
    public class Country
    {
        public string Name { get; set; }
        public string ThreeLetterAbbr { get; set; }
        public string TwoLetterAbbr { get; set; }
    }
 
    class Program
    {
        static void Main(string[] args)
        {
            var countryList = GetAllCountries();
        }
 
        public static IEnumerable<Country> GetAllCountries()
        {
            var countries = CultureInfo.GetCultures(CultureTypes.SpecificCultures)
                .Select(ci => new RegionInfo(ci.LCID))
                .Select(ri => new Country
                                  {
                                      Name = ri.EnglishName,
                                      ThreeLetterAbbr = ri.TwoLetterISORegionName,
                                      TwoLetterAbbr = ri.ThreeLetterISORegionName
                                  }).ToList();
            return countries;
        }
    }
}

Comments