用C#编写一个程序,实现用户自定义公式, 然后保存到数据库中, 每次使用到该公式时,只要提出来出来使用计算就行了。如: a*B-C/D请各位大侠赐教赐教!!!!!

解决方案 »

  1.   

    string formulate = string.Format("{0}*{1} - {2}/{3}", 1, 2, 4, 1);
    MSScriptControl.ScriptControl sc = new MSScriptControl.ScriptControlClass();
    sc.Language = "JavaScript";
    MessageBox.Show(sc.Eval(formulate).ToString())
      

  2.   

    你把字符串"{0}*{1} - {2}/{3}"存到数据库里就可以了string formulate = string.Format("{0}*{1} - {2}/{3}", 1, 2, 4, 1);
    DataTable dt = new DataTable();
    dt.Compute(formulate, "").ToString();
      

  3.   

    object o=new DataTable.Compute("1+2","");
    http://topic.csdn.net/u/20100617/10/b7ca5dae-3ad9-4d1b-94a9-7aa14d85a8a6.html
      

  4.   

    用DataTable吧,可以对传入的字符串格式的算式进行计算。