Add strongly typed quantities and units to your code and get merrily on with your life.
No more magic constants found online or guessing the unit of variables.
ℹ️ The master branch now targets v6, but it is still in pre-release.
New units will be backported to maintenance/v5 until v6 becomes stable.
Upgrading from 5.x to 6.x
Upgrading from 4.x to 5.x
🧪 Experimental: Check out UnitsNet.Modular, which generates only the quantities and units your application needs.
- Overview
- Installing via NuGet
- Static Typing
- Operator Overloads
- Culture and Localization
- Dynamically Parse Quantities and Convert to Units
- Custom units
- Example: Unit converter app
- Example: WPF app using IValueConverter to parse input
- Precision and Accuracy
- Serialize to JSON, XML and more
- Want To Contribute?
- Units.NET on other platforms
- Continuous Integration
- Who are Using This?
- Top Usages by GitHub Repos
Add it via CLI:
dotnet add package UnitsNetor go to NuGet Gallery | UnitsNet for detailed instructions.
- .NET Standard 2.0
- .NET 8.0 (LTS)
- .NET 9.0 (latest stable)
- .NET 10.0 (preview)
For C# 14 projects, use the new extension members syntax (no parentheses):
dotnet add package UnitsNet.NumberExtensions.CS14using UnitsNet.NumberExtensions.NumberToLength;
// C# 14 extension members syntax, without parantheses
Length distance = 5.Meters; // Instead of Length.FromMeters(5)Note: Requires 'preview' and .NET 10 SDK preview for now.
For C# 13 and lower (.NET SDK 9 or lower), use the classic extension methods:
dotnet add package UnitsNet.NumberExtensionsusing UnitsNet.NumberExtensions.NumberToLength;
// Classic extension methods, with parentheses
Length distance = 5.Meters(); // Instead of Length.FromMeters(5)// Construct
Length meter = Length.FromMeters(1);
Length twoMeters = new Length(2, LengthUnit.