C#中字符串转换为计算公式
添加COM引用:
private void button_Click(object sender, EventArgs e) { MSScriptControl.ScriptControl sc = new MSScriptControl.ScriptControlClass(); sc.Language = "JavaScript"; MessageBox.Show(sc.Eval("((2*3)-5+(3*4))+6/2").ToString());//1+12+3 }
运行结果:16
"唯有高屋建瓴,方可水到渠成"