Repository navigation
Getting Started
dotnet add package MarcusMedina.Units.TemperatureRequirements: .NET 10.0+, C# 14.0+
Every temperature value is represented by the Temperature struct, which always stores its magnitude internally in Kelvin. You never work with a raw double and hope you remember which scale it was in — instead, you create a Temperature from whichever scale fits the problem, and read it back out in whichever scale you need.
Creation and conversion are always separate extension methods:
- Creation:
80.DegreesReaumur()→ returns aTemperature - Conversion:
temperature.ToCelsius()→ returns adouble
Unlike the other Units packages, temperature scales aren't purely multiplicative — each carries its own offset and scale factor (Celsius, Fahrenheit, Réaumur, Delisle, Newton, Rømer are all affine, not linear, transforms of Kelvin). The Temperature struct handles that for you, so mixing scales in the same expression is still always safe.
One consequence of temperature being an affine scale: adding two absolute Temperature values together (100°C + 10°C) is physically meaningless, since Kelvin values don't compose that way. The + operator is marked [Obsolete] for exactly this reason — subtraction (a temperature difference) is fine, addition of two absolute temperatures is not.
using MarcusMedina.Units.Temperature.Metric;
using MarcusMedina.Units.Temperature.US;
using MarcusMedina.Units.Temperature.Historical;
// Create a Temperature from any supported scale
Temperature boiling = 100.DegreesCelsius();
Temperature oldScale = 80.DegreesReaumur();
Temperature outside = 68.DegreesFahrenheit();
// Convert to whatever scale you need
double fahrenheit = boiling.ToFahrenheit(); // 212
double celsius = oldScale.ToCelsius(); // 100
// Subtracting temperatures (a difference) is fine
Temperature cooler = boiling - 10.DegreesCelsius();
// Comparisons work across scales
bool hotter = boiling > oldScale;From here, see API Reference for the full list of supported scales per namespace.