CountriesInfo 1.0.0
See the version list below for details.
dotnet add package CountriesInfo --version 1.0.0
NuGet\Install-Package CountriesInfo -Version 1.0.0
<PackageReference Include="CountriesInfo" Version="1.0.0" />
paket add CountriesInfo --version 1.0.0
#r "nuget: CountriesInfo, 1.0.0"
// Install CountriesInfo as a Cake Addin #addin nuget:?package=CountriesInfo&version=1.0.0 // Install CountriesInfo as a Cake Tool #tool nuget:?package=CountriesInfo&version=1.0.0
CountriesInfo
A comprehensive .NET library for accessing detailed country information. Features include retrieving country details such as names, codes, capitals, continents, population, and area.
Installation
You can install the package via NuGet Package Manager Console:
Install-Package CountriesInfo
Or via .NET CLI:
dotnet add package CountriesInfo
Usage
Basic Usage
using CountriesInfo;
// Initialize the service
var countriesService = new CountriesService();
// Get all countries
var allCountries = countriesService.GetAllCountries();
// Get a specific country by code
var usa = countriesService.GetCountryByCode("US");
if (usa != null)
{
Console.WriteLine($"Country: {usa.Name}");
Console.WriteLine($"Capital: {usa.Capital}");
Console.WriteLine($"Population: {usa.Population:N0}");
Console.WriteLine($"Area: {usa.AreaKm2:N2} km²");
}
// Get countries by continent
var europeanCountries = countriesService.GetCountriesByContinent("Europe");
foreach (var country in europeanCountries)
{
Console.WriteLine($"{country.Name} - {country.Capital}");
}
Available Methods
GetAllCountries()
- Returns:
IEnumerable<Country>
- Description: Get a list of all countries
- Returns:
GetCountryByCode(string code)
- Returns:
Country?
- Description: Get a country by its code (e.g., "US", "GB")
- Returns null if country is not found
- Returns:
GetCountriesByContinent(string continent)
- Returns:
IEnumerable<Country>
- Description: Get all countries in a specific continent
- Returns:
Country Properties
The Country
class contains the following properties:
public class Country
{
public string Name { get; set; } // Country name
public string Code { get; set; } // Country code
public string Capital { get; set; } // Capital city
public string Continent { get; set; } // Continent name
public long Population { get; set; } // Population count
public double AreaKm2 { get; set; } // Area in square kilometers
}
Example Project
Here's a complete example showing how to use the package in a console application:
using CountriesInfo;
class Program
{
static void Main(string[] args)
{
var service = new CountriesService();
// Example 1: Print all country names and their capitals
Console.WriteLine("All Countries and Capitals:");
foreach (var country in service.GetAllCountries())
{
Console.WriteLine($"{country.Name}: {country.Capital}");
}
// Example 2: Find a specific country
var france = service.GetCountryByCode("FR");
if (france != null)
{
Console.WriteLine($"\nFrance Details:");
Console.WriteLine($"Capital: {france.Capital}");
Console.WriteLine($"Population: {france.Population:N0}");
Console.WriteLine($"Area: {france.AreaKm2:N2} km²");
}
// Example 3: List all countries in Asia
Console.WriteLine("\nAsian Countries:");
foreach (var country in service.GetCountriesByContinent("Asia"))
{
Console.WriteLine(country.Name);
}
}
}
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
MohaNed Ghawar (Rapid)
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net7.0
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.