Here is a simple Linq code to retrive the list of country code and names
C# code:
Also you need to add the below class
- public IEnumerable<Country> GetCountries()
- {
- var countryList = from r in
- from ci in CultureInfo.GetCultures(CultureTypes.SpecificCultures)
- select new RegionInfo(ci.LCID)
- group r by r.TwoLetterISORegionName into g
- select new Country
- {
- Code = g.Key,
- Name = g.First().DisplayName
- };
- return countryList;
- }
- class Country
- {
- public string Code { get; set; }
- public string Name { get; set; }
- }
No comments:
Post a Comment