• Source
    1. using System;
    2. using System.Data;
    3. using System.Windows.Forms;
    4.  
    5. namespace WindowsFormsApplication1
    6. {
    7. public partial class Form1 : Form
    8. {
    9. public Form1()
    10. {
    11. InitializeComponent();
    12. }
    13.  
    14. private void Form1_Load(object sender, EventArgs e)
    15. {
    16. Console.WriteLine(this.Evaluate("1+3*10/2")); // 16
    17. }
    18.  
    19. private decimal Evaluate(string exp)
    20. {
    21. var table = new DataTable();
    22. var column = table.Columns.Add();
    23. column.Expression = exp;
    24. var row = table.Rows.Add();
    25.  
    26. return decimal.Parse(row[0].ToString());
    27. }
    28. }
    29. }
    30.