• Stars3k+3 tuần này
  • Forks416
  • Watchers33
  • Issues14
  • Ngày tạo19/07/2013
  • Cập nhật gần nhất30/11/2026
  • Ngôn ngữC#
  • Giấy phépMIT-0
README.md85.4 KBRaw

CI Build Pull Requests .NET Framework 4.8 codecov StandWithUkraine

Units.NET

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.

Changes

ℹ️ 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

Add it via CLI:

dotnet add package UnitsNet

or go to NuGet Gallery | UnitsNet for detailed instructions.

Build Targets

  • .NET Standard 2.0
  • .NET 8.0 (LTS)
  • .NET 9.0 (latest stable)
  • .NET 10.0 (preview)

Extension Packages

UnitsNet.NumberExtensions.CS14 (C# 14 Extension Members)

For C# 14 projects, use the new extension members syntax (no parentheses):

dotnet add package UnitsNet.NumberExtensions.CS14
using 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.

UnitsNet.NumberExtensions (Classic)

For C# 13 and lower (.NET SDK 9 or lower), use the classic extension methods:

dotnet add package UnitsNet.NumberExtensions
using UnitsNet.NumberExtensions.NumberToLength;

// Classic extension methods, with parentheses
Length distance = 5.Meters();        // Instead of Length.FromMeters(5)

Static Typing

// Construct
Length meter = Length.FromMeters(1);
Length twoMeters = new Length(2, LengthUnit.

Nội dung README thuộc về angularsen và cộng đồng đóng góp, giấy phép MIT-0. Nguồn: github.com/angularsen/UnitsNet