我已經創建了一個類來處理C#中的單位轉換。它不工作,因爲它只應該返回字符串。你可以使用Enum for Double變量嗎?
下面是類:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace RestaurantManagementSystem
{
class unitHandler
{
public enum Units
{
Grams = 1,
KiloGrams = 0.001,
Milligram = 1000,
Pounds = 0.00220462,
Ounces = 0.035274,
Tonnes = 0.000001,
Litres = 1,
Millilitres = 1000,
Cups = 4.22675,
FluidOunces = 33.814,
TeaSpoon = 202.884,
TableSpoon = 67.628,
CubicFeet = 0.0353147,
CubicInch = 61.0237,
CubicCentimetres = 0.0001,
CubicMetres = 0.001
}
public double Convert_Value(Units from, Units to, double quantity)
{
double converted_quantity = 0;
double fromValue = quantity * Convert.ToDouble(from.ToString());
converted_quantity = fromValue * Convert.ToDouble(to.ToString());
return converted_quantity;
}
}
}
我會以某種方式要枚舉類型以包含的每個單元的轉換系數的雙值,則使用它們進行轉換並返回轉換量。
沒有,但你可以解釋整數點數。 – leppie