作者supertsao (Lawrence)
看板C_Sharp
标题[问题] 请问关於计算机的写法
时间Sat May 14 23:30:51 2011
关於计算号码按钮 我的写法是
private void btn1_Click(object sender, EventArgs e)
{
textBox1.Text += "1"; //当按1的时候 萤幕textBox1 显示1
}
我看老外新手教学的写法是
private bool inputStatus = true;
private void cmd1_Click(object sender, System.EventArgs e)
{
if (inputStatus)
{
txtInput.Text += cmd1.Text;
}
else
{
txtInput.Text = cmd1.Text;
inputStatus = true;
}
if里面的意思跟我的一样 我看不懂他为什麽要判断inputStatus
if和else 里面出现的结果有何差别?
原文在
http://www.dreamincode.net/forums/topic/32968-basic-calculator-in-c%23/
感谢回答
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 111.242.148.147
1F:→ james732:看起来是判断「要直接附加上去」或者「清掉原本数字」 05/14 23:34
2F:→ james732:inputStatus为false会清掉原本的内容,为true会附加上去 05/14 23:35
3F:→ sosokill:应该是按下等於的时候会变成false 直接显示答案 05/15 02:27
4F:→ sosokill:其他的就显是1+2+3这样子? 05/15 02:27