How do I create a generic converter for units of measurement in C#?

前端 未结 6 577
误落风尘
误落风尘 2021-01-31 06:48

I have been trying to learn a bit more about delegates and lambdas while working on a small cooking project that involves temperature conversion as well as some cooking measurem

6条回答
  •  误落风尘
    2021-01-31 07:04

    You could take a look at Units.NET. It's on GitHub and NuGet. It provides most common units and conversions, supports both static typing and enumeration of units and parsing/printing of abbreviations. It doesn't parse expressions though, and you can't extend existing classes of units, but you can extend it with new third party units.

    Example conversions:

    Length meter = Length.FromMeters(1);
    double cm = meter.Centimeters; // 100
    double feet = meter.Feet; // 3.28084
    

提交回复
热议问题