Skip to content

Getting Started

Marcus Ackre Medina edited this page Jul 20, 2026 · 1 revision

Getting Started

Install

dotnet add package MarcusMedina.Units.Speed

Requirements: .NET 10.0+, C# 14.0+

Philosophy

Every speed value is represented by the Speed struct, which always stores its magnitude internally in metres per second. You never work with a raw double and hope you remember which unit it was in — instead, you create a Speed from whichever unit fits the problem, and read it back out in whichever unit you need.

Creation and conversion are always separate extension methods:

  • Creation: 15.Knots() → returns a Speed
  • Conversion: speed.ToKilometersPerHour() → returns a double

Because both directions go through metres per second as the common base, you can freely mix units from different families (metric, US customary, nautical, scientific) in the same expression — arithmetic and comparisons just work.

First example

using MarcusMedina.Units.Speed.Metric;
using MarcusMedina.Units.Speed.Nautical;
using MarcusMedina.Units.Speed.Scientific;
using MarcusMedina.Units.Speed.US;

// Create a Speed from any supported unit
Speed car   = 120.KilometersPerHour();
Speed ship  = 15.Knots();
Speed jet   = 1.2.Mach();
Speed sprinter = 22.MilesPerHour();

// Convert to whatever unit you need
double mph = car.ToMilesPerHour();     // ≈ 74.6
double ms  = ship.ToMetersPerSecond(); // ≈ 7.72

// Arithmetic works directly on Speed values, mixing unit families freely
Speed total = car + 10.KilometersPerHour() + sprinter;

// Comparisons
bool faster = jet > car;

From here, see API Reference for the full list of supported units per namespace.

Clone this wiki locally