Skip to content
Marcus Ackre Medina edited this page Jul 20, 2026 · 2 revisions

MarcusMedina.Units.Volume

Fluent volume unit conversion for .NET 10+ — metric, US customary, British imperial, and historical Swedish units, all through a strongly-typed Volume struct.

dotnet add package MarcusMedina.Units.Volume

Why this exists

These came to me while I was sitting with upper-secondary students, helping them work through their maths homework. They saw calculations; I saw code. We'd break each problem down into small pieces so it was easier to grasp, and then they'd work through it themselves — usually landing on "oh, so that's all it was?" after sitting there feeling completely lost about what the task even wanted from them.

I wanted each unit conversion to be broken into the same small, obvious steps I'd walk a student through by hand, not buried inside a single formula. And a raw double can't stop you from mixing up a US gallon with a UK gallon — 3.785 L versus 4.546 L is a real difference, and it's exactly the kind of mistake a type system should catch for you.

Who this is for

  • New to C#? The library is small enough to read start to finish, and shows a clean example of extension methods and operator overloading.
  • Teaching or learning unit conversion? Every conversion factor sits next to its unit, documented, instead of being hidden inside a formula.
  • Building something real? Zero dependencies, strongly typed, and US/UK units of the same name are kept deliberately separate so they can't be confused by accident.

Pages

Quick Example

using MarcusMedina.Units.Volume.Metric;
using MarcusMedina.Units.Volume.British;
using MarcusMedina.Units.Volume.SwedishOld;

// Create a Volume from any supported unit
Volume bottle = 1.5.Liters();
Volume cask   = 1.Ankare();

// Convert to whatever unit you need
double gallonsUK = bottle.ToGallonUK();   // ≈ 0.33
double liters    = cask.ToLiters();       // ≈ 39.27

// Arithmetic works directly on Volume values
Volume total = bottle + 1.GallonUK();

// Comparisons
bool bigger = cask > bottle;

Links

Clone this wiki locally