Country Data In C#

When building applications in .NET that require you to fetch country and regions etc, we mostly use an API to fetch data over the network, however, this data most of the time doesn't change. In order to improve user experience by loading data faster, you might want to reduce network calls especially in mobile platforms. This will go a long way to reduce the data consumption of your users.
 
Country.Data.Standard is designed to provide offline relevant country information across all .Net Platforms, below is how you can use this library in your application to achieve your goals.
 
Install Library
  1. PM> Install-Package CountryData.Standard -Version 1.0.1  
Initialize the Country data object
  1. //loads all Country Data via the constructor (You can initialize this once as a singleton)  
  2. var helper = new CountryHelper()  
Get list of Countries
  1.    var countries = helper.GetCountries();  
  2.     foreach (var country in countries)  
  3.      {  
  4.        Console.WriteLine(country);  
  5.       }  
Get list of Regions in a Country by Country Code
  1.     var regions = helper.GetRegionByCountryCode("GH");  
  2.      foreach (var region in regions)  
  3.      {  
  4.       Console.WriteLine(region.Name);  
  5.      }  

Using lambda for custom querries

 
GetCountryData() returns an IEnumerable<Country> which can be queried with Lambda for a more flexible usage.
  1.      //example1  
  2.       var data = helper.GetCountryData();  
  3.        //get list of countries by their Names  
  4.       var countries = data.Select(c => c.CountryName).ToList();  
  5.        foreach (var country in countries)  
  6.        {  
  7.         Console.WriteLine(country);  
  8.        }  
  9.          
  10.          
  11.        //example 2  
  12.        data.Where(x => x.CountryShortCode == "US")  
  13.                               .Select(r=>r.Regions).FirstOrDefault()  
  14.                               .ToList();  
Adding this library to any .NET solution makes it easy for you to access offline country Data. You can contribute to this library here. All contributions are welcomed.