Repository navigation
Getting Started
Marcus Ackre Medina edited this page Sep 13, 2026
·
2 revisions
dotnet add package MarcusMedina.Units.DistanceTargets net10.0 (C# 14.0).
using MarcusMedina.Units.Distance.Metric;
using MarcusMedina.Units.Distance.Astronomical;
using MarcusMedina.Units.Distance.SwedishOld;
// Create a Distance from any supported unit
Distance trip = 42.Kilometers();
Distance star = 4.24.LightYears();
// Convert to whatever unit you need
double miles = trip.ToMiles(); // ≈ 26.1 (needs MarcusMedina.Units.Distance.British)
double parsecs = star.ToParsecs(); // ≈ 1.3
// Historical Swedish units work the same way
Distance oldMap = 10.Alnar();
// Arithmetic works directly on Distance values
Distance total = trip + 1.SwedishMiles();
// Comparisons
bool farther = star > trip;Distance is a readonly struct that always stores its value internally as meters. Every unit family — metric, US customary, British (current and historical), Swedish (modern and historical), astronomical, and microscopic — is just a pair of extension methods: one that creates a Distance by converting a raw number into meters, and one (To...()) that converts back out. Because every Distance shares the same internal representation, you can freely mix units from wildly different scales in the same expression — kilometers plus Swedish miles, or light-years compared against a road trip — without ever risking a unit mismatch.
- API Overview for the full list of unit extension methods and conversion factors
- Advanced Usage for operators, comparisons, formatting, and a couple of easter eggs