public static object Eval(string AExpression) { try { return new System.Data.DataTable().Compute(AExpression, ""); } catch { return null; } } private void button1_Click(object sender, EventArgs e) { lblResult.Text = Eval("(1.5+2.5)*2/4").ToString(); }
转载于:https://www.cnblogs.com/flying19880517/archive/2009/06/29/DataTable_Compute_Expression_Calculation.html