Skip to content

Advanced Usage

Marcus Ackre Medina edited this page Sep 13, 2026 · 2 revisions

Advanced Usage

Most of what there is to know about MarcusMedina.Units.Weight lives on the API Reference page. This page covers the parts that go beyond simple creation and conversion.

Five unit systems, one type

Weight is the single common representation (grams internally) for five otherwise-incompatible historical and modern systems: Metric, US, British, BritishOld (Troy/Apothecary), and SwedishOld. Because they all resolve to the same struct, values from different systems combine freely:

using MarcusMedina.Units.Weight.Metric;
using MarcusMedina.Units.Weight.British;
using MarcusMedina.Units.Weight.BritishOld;

Weight mixed = 1.Kilograms() + 1.Stone() + 1.TroyOunces();

Where systems overlap — and where they diverge

Several unit names appear in more than one namespace, and it matters whether they mean the same thing:

  • Grains() — identical (0.06479891 g) across British, US, and BritishOld (as TroyGrains()). Historically the grain was the one unit all these systems agreed on.
  • Ounces() / Pounds() — identical between British and US (28.349523125 g / 453.59237 g). Both use the same avoirdupois ounce/pound.
  • Ounces() on BritishOld — there is no plain Ounces() there; it's TroyOunces() (31.1034768 g) and ApothecaryOunces() (also 31.1034768 g, same value, different lineage) — deliberately distinct names from the avoirdupois Ounces(), because a Troy ounce is not an avoirdupois ounce.
  • Tons diverge: British.LongTons() (2240 lb, 1 016 046.9088 g) vs. US.ShortTons() (2000 lb, 907 184.74 g) are different methods on purpose — there's no bare Tons().

As with the sibling Volume package, the rule is: if two systems disagree on a unit's size, the library gives them different method names rather than letting you guess which one you got.

Arithmetic and ratios

Weight supports +, -, and scaling by a double via * / /. Dividing two Weight values (rather than a Weight by a double) returns a plain double ratio:

Weight doubled = 1.Stone() * 2;
double ratio   = 1.LongTons() / 1.ShortTons(); // ≈ 1.12

Comparisons and sorting

Weight implements IComparable<Weight> and IEquatable<Weight> plus the full comparison operator set, so a List<Weight> sorts correctly out of the box:

var weights = new List<Weight> { 1.Stone(), 1.TroyPounds(), 1.Skålpund() };
weights.Sort();

ToString formatting

Weight.ToString() always renders the underlying gram value in invariant culture, e.g. "453.59237 g", regardless of which unit the value was created from.

Clone this wiki locally