我做了一个 GUI 计算器。因此,当有人按下按钮时,数字和符号会显示在标签中,然后当他们按下 Enter 时,计算机会捕获字符串,这就是我需要帮助的地方。我知道在 Python 中有一个可以使用的 eval 语句,在 C# 中有类似的东西。
如果有帮助,这是代码。具体看方法button_click
public class form1 : Form
{
    private Label lab;
    private Button button2;
    private Button button;
    private Button plus;
    private MathFunctions.MathParser calc;
    public static void Main()
    {
        Application.Run(new form1());
    }
    public form1()
    {
       // Initialize controls
       ...
    }
    private void button_Click(object sender,System.EventArgs e)
    {
        string answer = lab.Text;
    }
    private void button2_Click(object sender,System.EventArgs e)
    {
        lab.Text = lab.Text + "2";
    }
    private void button_plus(object sender,System.EventArgs e)
    {
        lab.Text = lab.Text + "+";
    }
}