-
Notifications
You must be signed in to change notification settings - Fork 0
Getting Started
Marcus Ackre Medina edited this page Jul 20, 2026
·
1 revision
dotnet add package MarcusMedina.Units.SpeedRequirements: .NET 10.0+, C# 14.0+
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 aSpeed - Conversion:
speed.ToKilometersPerHour()→ returns adouble
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.
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.