私はGUI計算機を作った。だから、誰かがボタンを押すと数字と記号がラベルに表示されます。そして、Enterキーを押すとコンピュータが文字列をキャプチャし、それがどこかの助けを必要とします。私は、Pythonには、C#で何か似たようなものが使用できるevalステートメントがあることを知っています。文字列として与えられた算術式を評価する方法
これが役立つ場合は、ここにコードがあります。 は、特にあなたが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 + "+";
}
}
何が起こりたくないのですか?できるだけ具体的なものにする –
可能な重複はありますか? http://stackoverflow.com/questions/355062/is-there-a-string-math-evaluator-in-net – Josh
今後の質問のためにコードサンプルをいくつかの行に凝縮させてください。この中に無関係なコードが多すぎます。 –