UnitsNet is a library for .Net that greatly simplifies working with unit variables representing physical quantities.
You’ve probably experienced the minor hell of having to manage dimensions, areas, mass measurements… when different units are involved, and how cumbersome it is to consider all possible implications.
Units.Net provides the functions to handle quantities. It includes over 1000 units of 95 types of physical quantities, such as length, mass, force, time, pressure.
Creating a physical quantity in Units.Net is as simple as initializing it from one of the static methods
Length meter = Length.FromMeters(1);
Length twoMeters = new Length(2, LengthUnit.Meter);
From there, we can operate with them, and Units.Net will perform the appropriate handling for them.
Length l1 = 2 * Length.FromMeters(1);
Length l2 = Length.FromMeters(1) / 2;
Length l3 = l1 + l2;
Of course, we can perform more complex operations involving multiple units. Units.Net will throw an exception if any of the operations is not consistent with its units.
Length distance = Speed.FromKilometersPerHour(80) * TimeSpan.FromMinutes(30);
Acceleration a1 = Speed.FromKilometersPerHour(80) / TimeSpan.FromSeconds(2);
Acceleration a2 = Force.FromNewtons(100) / Mass.FromKilograms(20);
RotationalSpeed r = Angle.FromDegrees(90) / TimeSpan.FromSeconds(2);
Units.Net includes many more interesting functions, covering most of the needs we have when dealing with unit variables. These functions include conversion, parsing, serialization, string conversion in multiple languages.
Furthermore, it is possible to extend it with our own units, including a definition in a Json file. Although the library includes most of the units you might need in your projects.
Units.Net is Open Source and the code is available at https://github.com/angularsen/UnitsNet.
Additionally, it is available as a Nuget package to conveniently add to our projects, and it is compatible with .Net Framework and .Net Standard.

