public static object MsBase(string dim, UInt16 opt = 0)
{
string pattern = @"\d+\*\d+\*\d+";
if (Regex.IsMatch(dim,pattern))
{
string tmp = Regex.Match(dim, pattern).Value;
string[] arg = Regex.Split(tmp, @"/*");
double L = Convert.ToDouble(arg[0]) / 1000;
double W = Convert.ToDouble(arg[1]) / 1000;
double H = Convert.ToDouble(arg[2]) / 1000;
Box myclass = new Box(L,W,H);
if (opt == 0) { return myclass.Cube(); }
if (opt == 1) { return myclass.SideArea(); }
else { return ExcelError.ExcelErrorNA; }
}
else { return ExcelError.ExcelErrorNA; }
}
}
[C#] 纯文本查看复制代码
public class Box
{
public double L { get; set; }
public double W { get; set; }
public double H
{
get; set;
}
public bool IsValid { get; set; }
// Constructor
public Box(double param1,double param2,double param3)
{
L = param1;
W = param2;
H = param3;
}
//Function
public double Cube() { return L * W * H; }
public double SideArea() { return 2 * (L + W) * H; }
public double BottomArea() { return L * W; }
}
}