Home | Contact Us

CSharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript

C# Country Name Arrays

This C# article presents an array containing country data. It is useful if country data is required.

Country names can be stored in an array.

This is useful for drop-down lists and forms in C# programs. It allows us to avoid the burden of getting this data manually. We show a C# class that stores country names and abbreviations.

Example. First, the data I used to generate this code are from an established SQL script, available on the Internet. To generate the C# arrays, I wrote a program that combined regular expressions and loops.

Note: The following class contains all the country abbreviations and names in string arrays.

String Array

Class that stores country names: C#

/// <summary>
/// Static country name arrays
/// </summary>
static class CountryArrays
    /// <summary>
    /// Country names
    /// </summary>
    public static string[] Names = new string[]
	"American Samoa",
	"Antigua and Barbuda",
	"Bosnia and Herzegovina",
	"Bouvet Island",
	"British Indian Ocean Territory",
	"Brunei Darussalam",
	"Burkina Faso",
	"Cape Verde",
	"Cayman Islands",
	"Central African Republic",
	"Christmas Island",
	"Cocos (Keeling) Islands",
	"Congo, the Democratic Republic of the",
	"Cook Islands",
	"Costa Rica",
	"Cote D'Ivoire",
	"Czech Republic",
	"Dominican Republic",
	"El Salvador",
	"Equatorial Guinea",
	"Falkland Islands (Malvinas)",
	"Faroe Islands",
	"French Guiana",
	"French Polynesia",
	"French Southern Territories",
	"Heard Island and Mcdonald Islands",
	"Holy See (Vatican City State)",
	"Hong Kong",
	"Iran, Islamic Republic of",
	"Korea, Democratic People's Republic of",
	"Korea, Republic of",
	"Lao People's Democratic Republic",
	"Libyan Arab Jamahiriya",
	"Macedonia, the Former Yugoslav Republic of",
	"Marshall Islands",
	"Micronesia, Federated States of",
	"Moldova, Republic of",
	"Netherlands Antilles",
	"New Caledonia",
	"New Zealand",
	"Norfolk Island",
	"Northern Mariana Islands",
	"Palestinian Territory, Occupied",
	"Papua New Guinea",
	"Puerto Rico",
	"Russian Federation",
	"Saint Helena",
	"Saint Kitts and Nevis",
	"Saint Lucia",
	"Saint Pierre and Miquelon",
	"Saint Vincent and the Grenadines",
	"San Marino",
	"Sao Tome and Principe",
	"Saudi Arabia",
	"Serbia and Montenegro",
	"Sierra Leone",
	"Solomon Islands",
	"South Africa",
	"South Georgia and the South Sandwich Islands",
	"Sri Lanka",
	"Svalbard and Jan Mayen",
	"Syrian Arab Republic",
	"Taiwan, Province of China",
	"Tanzania, United Republic of",
	"Trinidad and Tobago",
	"Turks and Caicos Islands",
	"United Arab Emirates",
	"United Kingdom",
	"United States",
	"United States Minor Outlying Islands",
	"Viet Nam",
	"Virgin Islands, British",
	"Virgin Islands, US",
	"Wallis and Futuna",
	"Western Sahara",

    /// <summary>
    /// Country abbreviations
    /// </summary>
    public static string[] Abbreviations = new string[]

We see a static class that contains two public static arrays. They will only be stored once in memory. The first array contains the country names with uppercase and lowercase letters. The second array contains two-letter abbreviations.

Static ClassStatic Array

Info: The arrays were generated from SQL insert scripts I found elsewhere, and no edits to the contents were made by me.

Country Name List

You can assign these arrays to the DataSource property on your ListBox or DropDown in Windows Forms. You can build a Dictionary from the strings for faster search time. The arrays correspond to each other.


Note: This means that CountryArrays.Names[5] is the name for CountryArrays.Abbreviations[5]. You may want to develop some helper methods.

Summary. We saw a country array class for C# that I generated with a regular expression. I did not type this manually, so there is a lower risk of mistakes. You can access these arrays with array indexes. This is efficient.