[Visual C#] DataTable Compute方法计算表达式
1 public static object Eval(string AExpression)
2 {
3 try
4 {
5 return new System.Data.DataTable().Compute(AExpression, "");
6 }
7 catch
8 {
9 return null;
10 }
11 }
2 {
3 try
4 {
5 return new System.Data.DataTable().Compute(AExpression, "");
6 }
7 catch
8 {
9 return null;
10 }
11 }
Example:
string text = Eval("(1.5+2.5)*2/4").ToString();
MessageBox.Show(text);