Repository navigation
Advanced Usage
Most of what there is to know about MarcusMedina.Units.Temperature lives on the API Reference page. This page covers the parts that go beyond simple creation and conversion — mainly the consequences of temperature being an affine scale rather than a purely multiplicative one.
Every other MarcusMedina.Units.* package can add two values of the same type and get a physically meaningful result (10 kg + 5 kg = 15 kg). Temperature can't: 100°C + 10°C is not 110°C, because Celsius (and Fahrenheit, Réaumur, etc.) are offset scales relative to Kelvin, not proportional ones.
Temperature a = 100.DegreesCelsius();
Temperature b = 10.DegreesCelsius();
#pragma warning disable CS0618
Temperature wrong = a + b; // compiles, but is physically meaningless
#pragma warning restore CS0618The + operator still exists (so generic code isn't broken) but is marked [Obsolete], so using it produces a compiler warning (CS0618) unless explicitly suppressed. If you genuinely need to sum raw Kelvin values for some other purpose, go through .Kelvin directly:
double sumKelvin = a.Kelvin + b.Kelvin;Subtraction is fine and stays a normal operator — boiling - 10.DegreesCelsius() is a well-defined temperature difference expressed by adjusting the Kelvin value.
Because every scale ultimately creates a Temperature backed by Kelvin, values from different namespaces can be compared and subtracted directly, no manual conversion needed:
using MarcusMedina.Units.Temperature.Metric;
using MarcusMedina.Units.Temperature.US;
using MarcusMedina.Units.Temperature.Historical;
bool hotter = 100.DegreesCelsius() > 200.DegreesFahrenheit();
Temperature diff = 80.DegreesReaumur() - 32.DegreesFahrenheit();Dividing two Temperature values returns a plain double — the ratio of their Kelvin values (thermodynamically meaningful, unlike a ratio of Celsius readings would be):
double ratio = 200.Kelvin() / 100.Kelvin(); // 2.0Temperature.ToString() always renders the Kelvin value using invariant culture, e.g. "273.15 K", regardless of which scale the value was created from.