Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【开源项目】UnitsNet #750

Closed
gaufung opened this issue Nov 2, 2024 · 1 comment
Closed

【开源项目】UnitsNet #750

gaufung opened this issue Nov 2, 2024 · 1 comment

Comments

@gaufung
Copy link
Collaborator

gaufung commented Nov 2, 2024

https://github.com/angularsen/UnitsNet

@gaufung
Copy link
Collaborator Author

gaufung commented Nov 26, 2024

UnitsNet 是 C# 中处理各种物理单位的库,比如以长度为例,有 , 英尺, 海里 等等。通常我们需要查阅相关的资料来了解他们之间的转换关系,过程非常繁琐。但是 UnitsNet 库解决了我们的痛点,这样就不用在复杂的转换中引入错误。

using UnitsNet;

Length length = Length.FromMeters(1);
Console.WriteLine(length);
Length length1 = new Length(2, UnitsNet.Units.LengthUnit.Meter);


System.Console.WriteLine($"cm: {length.Centimeters}");
System.Console.WriteLine($"m: {length.Meters}");
System.Console.WriteLine($"km: {length.Kilometers}");
System.Console.WriteLine($"in: {length.Inches}");
System.Console.WriteLine($"ft: {length.Feet}");
System.Console.WriteLine($"yd: {length.Yards}");
System.Console.WriteLine($"mi: {length.Miles}");
System.Console.WriteLine($"nmi: {length.NauticalMiles}");

1 m
cm: 100
m: 1
km: 0.001
in: 39.37007874015748
ft: 3.280839895013123
yd: 1.0936132983377078
mi: 0.0006213711922373339
nmi: 0.0005399568034557236

@gaufung gaufung closed this as completed Dec 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant