作者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