ISO 3166 Country Codes library for C#


The purpose of ISO 3166 is to define internationally recognized codes of letters and/or numbers that we can use when we refer to countries and their subdivisions. However, it does not define the names of countries – this information comes from United Nations sources (Terminology Bulletin Country Names and the Country and Region Codes for Statistical Use maintained by the United Nations Statistics Divisions).

Using codes saves time and avoids errors as instead of using a country’s name (which will change depending on the language being used), we can use a combination of letters and/or numbers that are understood all over the world.

For example, all national postal organizations throughout the world exchange international mail in containers identified with the relevant country code. Internet domain name systems use the codes to define top-level domain names such as “.fr” for France, “.au” for Australia. In addition, in machine-readable passports, the codes are used to determine the nationality of the user and, when we send money from one bank to another, the country codes are a way to identify where the bank is based.

ISO 3166 has three parts: codes for countries, codes for subdivisions and formerly used codes (codes that were once used to describe countries but are no longer in use).

  • The country codes can be represented either as a two-letter code (alpha-2) which is recommended as the general-purpose code, a three-letter code (alpha-3) which is more closely related to the country name and a three-digit numeric code (numeric-3) which can be useful if you need to avoid using Latin script.
  • The codes for subdivisions are represented as the alpha-2 code for the country, followed by up to three characters. For example ID-RI is the Riau province of Indonesia and NG-RI is the Rivers province in Nigeria. Names and codes for subdivisions are usually taken from relevant official national information sources.
  • The formerly used codes are four-letter codes (alpha-4). How the alpha-4 codes are constructed depends on the reason why the country name has been removed.

This C# Library (NuGet Gallery | devcoons.ISO3166 1.0.0) provides you an easy-to-use implementation of the ISO3166. Please check the following example of usage:

        static void Main(string[] args)

            ISO3166.ISO3166 obj = new ISO3166.ISO3166();

            // Get available list of continents
            var listOfContinents = obj.Continents;

            // Set as selected continent (a random continent from the list)
            obj.Continent = listOfContinents.ElementAt((new Random()).Next(1, listOfContinents.Count - 1)).Key;

            // Get available list of countries (based on selected continent)
            var listOfCountries = obj.Countries;

            // Set as selected country (a random country from the list)
            obj.Country = listOfCountries.ElementAt((new Random()).Next(1, listOfCountries.Count - 1)).Key;

            // Get available list of Subdivisions (based on selected country)
            var listOfSubdivisions = obj.Subdivisions;

            // Set as selected subdivision (a random subdivision from the list)
            obj.Subdivision = listOfSubdivisions.ElementAt((new Random()).Next(1, listOfSubdivisions.Count - 1)).Key;


devcoons/iso3166-countrycodes (

Disclaimer: The present content may not be used for training artificial intelligence or machine learning algorithms. All other uses, including search, entertainment, and commercial use, are permitted.