.NET units class, inches to millimeters

前端 未结 7 808
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-04 07:42

Does .NET has Units conversion class? I need to convert inches to millimeters and vise versa.

7条回答
  •  情话喂你
    2021-01-04 07:51

    No, you need to make one yourself, like this:

    public class Length
    {
        private const double MillimetersPerInch = 25.4;
        private double _Millimeters;
    
        public static Length FromMillimeters(double mm)
        {
             return new Length { _Millimeters = mm };
        }
    
        public static Length FromInch(double inch)
        {
             return new Length { _Millimeters = inch * MillimetersPerInch };
        }
    
        public double Inch { get { return _Millimeters / MillimetersPerInch; } } 
        public double Millimeters { get { return _Millimeters; } }
    }
    

提交回复
热议问题