Country Class

Provides utilities for working with countries and region information.

public static class Country

Example

var region = new RegionInfo("US");
string flag = Country.GetUnicodeFlag(region);
Assert.Equal("\U0001F1FA\U0001F1F8", flag); // US flag emoji

string flag2 = Country.GetUnicodeFlag("FR");
Assert.Equal("\U0001F1EB\U0001F1F7", flag2); // FR flag emoji

Methods

NameDescription
GetUnicodeFlag(RegionInfo)Gets the Unicode flag emoji for the specified region.
GetUnicodeFlag(string)Gets the Unicode flag emoji for the specified two-letter ISO region code.
TryGetUnicodeFlag(RegionInfo?, string?)Tries to get the Unicode flag emoji for the specified region.
TryGetUnicodeFlag(string?, string?)Tries to get the Unicode flag emoji for the specified two-letter ISO region code.

GetUnicodeFlag overloads

GetUnicodeFlag(RegionInfo)

Country.cs

Gets the Unicode flag emoji for the specified region.

public static string GetUnicodeFlag(RegionInfo region)
Parameters
region RegionInfo
Returns

string

Exceptions
ArgumentException
The two-letter ISO region name of region is not made of two ASCII letters, such as 419 for es-419.

GetUnicodeFlag(string)

Country.cs

Gets the Unicode flag emoji for the specified two-letter ISO region code.

public static string GetUnicodeFlag(string twoLetterISORegionName)
Parameters
twoLetterISORegionName string
Returns

string

Exceptions
ArgumentException
twoLetterISORegionName is not made of two ASCII letters.

TryGetUnicodeFlag overloads

TryGetUnicodeFlag(RegionInfo?, string?)

Country.cs

Tries to get the Unicode flag emoji for the specified region.

public static bool TryGetUnicodeFlag(RegionInfo? region, out string? flag)
Parameters
region RegionInfo?
flag string?
Returns

bool true if region is not null and its two-letter ISO region name is made of two ASCII letters; otherwise, false.

TryGetUnicodeFlag(string?, string?)

Country.cs

Tries to get the Unicode flag emoji for the specified two-letter ISO region code.

public static bool TryGetUnicodeFlag(string? twoLetterISORegionName, out string? flag)
Parameters
twoLetterISORegionName string?
flag string?
Returns

bool true if twoLetterISORegionName is made of two ASCII letters; otherwise, false.