CountriesInfo 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package CountriesInfo --version 1.0.0                
NuGet\Install-Package CountriesInfo -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CountriesInfo" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CountriesInfo --version 1.0.0                
#r "nuget: CountriesInfo, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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

  1. GetAllCountries()

    • Returns: IEnumerable<Country>
    • Description: Get a list of all countries
  2. GetCountryByCode(string code)

    • Returns: Country?
    • Description: Get a country by its code (e.g., "US", "GB")
    • Returns null if country is not found
  3. GetCountriesByContinent(string continent)

    • Returns: IEnumerable<Country>
    • Description: Get all countries in a specific continent

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 86 12/24/2024
1.0.1 86 12/23/2024
1.0.0 92 12/22/2024