CountrySC 1.2.0
dotnet add package CountrySC --version 1.2.0
NuGet\Install-Package CountrySC -Version 1.2.0
<PackageReference Include="CountrySC" Version="1.2.0" />
<PackageVersion Include="CountrySC" Version="1.2.0" />
<PackageReference Include="CountrySC" />
paket add CountrySC --version 1.2.0
#r "nuget: CountrySC, 1.2.0"
#:package CountrySC@1.2.0
#addin nuget:?package=CountrySC&version=1.2.0
#tool nuget:?package=CountrySC&version=1.2.0
<p align="center"> <img src=".github/images/banner.svg" alt="CountrySC - offline Countries, States, Cities for .NET" width="100%" /> </p>
CountrySC
A lightweight .NET library providing a complete, offline dataset of countries, states/provinces, and cities β with ISO country codes, flag emojis, and international dial codes derived on the fly. No API calls, no network dependency; the dataset ships embedded (Brotli-compressed) inside the package.
Install
dotnet add package CountrySC
Targets net10.0.
Quick start
using CountrySC;
var geo = new CountrySCService();
// All countries, sorted alphabetically by name
IEnumerable<Country> countries = geo.GetAll();
// Look up a country by its 2-letter ISO code (case-insensitive)
Country? us = geo.GetByCountryCode("US");
Console.WriteLine($"{us!.FlagEmoji} {us.Name} (+{us.PhoneCode})"); // πΊπΈ United States (+1)
// States/provinces for a country
IEnumerable<State> states = geo.GetStates("US");
// Cities for a given country + state id
var california = states.First(s => s.Name == "California");
IEnumerable<City> cities = geo.GetCities("US", california.Id);
// Find every country sharing an international dial code
IEnumerable<Country> plusOne = geo.GetByPhoneCode("+1"); // US, CA, ...
// IANA time zones for a country
IEnumerable<TimeZoneEntry> zones = geo.GetTimeZones("US"); // America/New_York, America/Chicago, ...
TimeSpan? offset = zones.First().CurrentUtcOffset;
// Official language(s) for a country
IEnumerable<string> languages = geo.GetLanguages("CH"); // French, German, Italian, Romansh
// Square SVG flag icon for a country (raw markup)
string flagSvg = geo.GetFlagSvg("US");
// Currency details for a country (e.g. United States Dollar, USD, $)
CountryCurrency? currency = geo.GetCurrency("US");
// Capital city of a country
string capital = geo.GetCapitalCity("US"); // Washington, D.C.
// Continent of a country
Continent? continent = geo.GetContinent("US"); // Continent.Americas
// Or via country properties:
string currencyName = us.Currency; // "United States Dollar"
string currencyIso = us.Iso4217; // "USD"
string currencySymbol = us.Symbol; // "$"
string capitalCity = us.CapitalCity; // "Washington, D.C."
Continent continentProperty = us.Continent; // Continent.Americas
API
CountrySCService
| Method | Description |
|---|---|
GetAll() |
All countries, sorted alphabetically by name. |
GetByCountryCode(string countryCode) |
Finds a country by ISO 3166-1 alpha-2 code (e.g. "US", "GB", "GR"). Case-insensitive; returns null if not found. |
GetByPhoneCode(string phoneCode) |
Finds all countries matching an e.164 dial code (e.g. "1" or "+1"). |
GetStates(string? countryCode) |
States/provinces for a country, sorted alphabetically. Empty if the country code is missing or unknown. |
GetCities(string? countryCode, int? stateId) |
Cities for a given country + state id, sorted alphabetically. Empty if either argument is missing or unknown. |
GetTimeZones(string? countryCode) |
IANA time zones observed in a country (e.g. "America/New_York"). Empty if the country code is missing or unknown. |
GetLanguages(string? countryCode) |
Official language(s) of a country (e.g. "English"). Empty if the country code is missing or unknown. |
GetFlagSvg(string? countryCode) |
Raw SVG markup of a country's square flag icon. Empty string if the country code is missing, unknown, or has no embedded icon. |
GetCurrency(string? countryCode) |
Gets the currency details for a given 2-letter country code. Returns null if the country code is missing or unknown. |
| GetCapitalCity(string? countryCode) | Gets the capital city for a given 2-letter country code. Returns string.Empty if the country code is missing or unknown. |
GetContinent(string? countryCode) |
Gets the continent for a given 2-letter country code. Returns null if the country code is missing or unknown. |
Properties
CountryβId,Name,States, plus computed properties:CountryCodeβ ISO alpha-2 code, derived from the flag emoji's Unicode codepointsFlagEmojiβ the flag emoji (e.g. πΊπΈ)PhoneCodeβ international dialing code (e.g."1","44")Exampleβ a sample local phone number for the countryDisplayNameβ"United States (US)"TimeZonesβ the country'sTimeZoneEntrylistOfficialLanguagesβ the country's official language name(s)FlagSvgβ raw SVG markup of the country's square flag icon, empty string if unavailableCurrencyβ name of the country's currency (e.g."United States Dollar")Iso4217β three-letter ISO 4217 currency code (e.g."USD")Symbolβ currency symbol (e.g."$"or"β¬")CapitalCityβ capital city of the country (e.g."Washington, D.C.")Continentβ continent where the country is located (Africa,Americas,Antarctica,Asia,Europe,Oceania)
StateβId,Name,CitiesCityβId,NameCountryCurrencyβCurrency(name of the currency),Iso4217(three-letter code),Symbol(symbol)TimeZoneEntryβZoneName(IANA identifier),CountryCode, plus computed properties:BaseUtcOffsetβ standard (non-DST) UTC offset, resolved from the local system's time zone databaseCurrentUtcOffsetβ UTC offset right now, including DST if in effect
Time zone data covers 246 countries/territories (418 zones total). Only IANA zone names are embedded; UTC offsets are resolved live via TimeZoneInfo so they stay correct across DST transitions instead of going stale.
Official language data covers 201 countries/territories. Coverage follows the source article and skips a handful of micro-territories and a few disputed/partially-recognized territories not present in the country dataset.
Currency data covers 250 countries/territories. Sourced from the Geocountries currency database (https://www.geocountries.com/country/currencies).
Capital city data covers 250 countries/territories. Sourced from Worlddata (https://www.worlddata.info/capital-cities.php).
Continent data covers 250 countries/territories. Sourced from Worlddata (https://www.worlddata.info/capital-cities.php).
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.