Repository navigation
Getting Started
Marcus Ackre Medina edited this page Sep 13, 2026
·
2 revisions
dotnet add package MarcusMedina.Units.EnergyTargets net10.0 (C# 14.0).
using MarcusMedina.Units.Energy.Metric;
using MarcusMedina.Units.Energy.Scientific;
// Create an Energy from any supported unit
Energy meal = 650.Kilocalories();
Energy photon = 2.5.Electronvolts();
// Convert to whatever unit you need
double kilojoules = meal.ToKilojoules(); // ≈ 2719.6
double joules = photon.ToJoules(); // ≈ 4.0e-19
// Arithmetic works directly on Energy values
Energy total = meal + 1.Kilojoules();
// Comparisons
bool bigger = meal > photon;Energy is a readonly struct that always stores its value internally as joules. Every unit family — metric (including electrical watt-hour units), scientific (electronvolts, ergs, calories, TNT equivalent), and US customary (BTU, foot-pound, therm) — is just a pair of extension methods: one that creates an Energy by converting a raw number into joules, and one (To...()) that converts back out. Because every Energy shares the same internal representation, you can freely mix a chemistry-textbook kilocalorie with a physics-textbook electronvolt in the same expression without ever risking a unit mismatch.
- API Overview for the full list of unit extension methods and conversion factors
- Advanced Usage for operators, comparisons, and formatting