所謂的計畫趕不上變化,變化趕不上老闆的一句話
當初在面試的時候雖然已經很定位的跟面試主管說致力想學跟寫Android這一塊
但最近微軟的新7.5芒果機一推出來,由於客戶需求,主管派我去聽微軟開的msdn程式開發講座
課程目前還再進行,講座是免費的,有興趣的朋友趕快報名
我還很帥氣的上了鏡頭,照片連結(其實那個角度我覺得拍得很醜 = =")
所以既然都已經聽完課了,當然就要先來個hello mango了
不過微軟的開發工具跟往常一樣,都是安裝完後compiler就可以有hello word的介面
所以我就寫一個Hello 計算機來測試看看囉!!! 我主要是仿微軟內建的計算計算方式,而且把功能更簡化(反正只是測試用的)
我特別把註解寫得很清楚,讓剛程式入門的新手,能更明確的了解程式是怎麼一回事。由於這是我第一次寫C#這種語言,若有錯的地方請不另請指教。
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using Microsoft.Phone.Controls; namespace Calc { public partial class MainPage : PhoneApplicationPage { public string number = ""; //用來顯示輸入的數字 public long temp = 0; //存放暫時的運算元 public double equal = 0; //存放等於的結果 public char oper = ' '; //存放運算元 public bool operClick = false; //用來判別是否有重複按壓運算子做運算子更換 // Constructor public MainPage() { InitializeComponent(); } private void btn0_Click(object sender, RoutedEventArgs e) { if (number == "0") number = ""; //預防一開始的0可以無限點擊變成00000.... number += 0; //輸入的數字 temp = int.Parse(number); //字串轉成整數的數字 PageTitle.Text = number; //顯示在顯示器上 operClick = false; //無重複按壓運算子 } private void btn1_Click(object sender, RoutedEventArgs e) { if (number == "0") number = ""; number += 1; temp = int.Parse(number); PageTitle.Text = number; operClick = false; } private void btn2_Click(object sender, RoutedEventArgs e) { if (number == "0") number = ""; number += 2; temp = int.Parse(number); PageTitle.Text = number; operClick = false; } private void btn3_Click(object sender, RoutedEventArgs e) { if (number == "0") number = ""; number += 3; temp = int.Parse(number); PageTitle.Text = number; operClick = false; } private void btn4_Click(object sender, RoutedEventArgs e) { if (number == "0") number = ""; number += 4; temp = int.Parse(number); PageTitle.Text = number; operClick = false; } private void btn5_Click(object sender, RoutedEventArgs e) { if (number == "0") number = ""; number += 5; temp = int.Parse(number); PageTitle.Text = number; operClick = false; } private void btn6_Click(object sender, RoutedEventArgs e) { if (number == "0") number = ""; number += 6; temp = int.Parse(number); PageTitle.Text = number; operClick = false; } private void btn7_Click(object sender, RoutedEventArgs e) { if (number == "0") number = ""; number += 7; temp = int.Parse(number); PageTitle.Text = number; operClick = false; } private void btn8_Click(object sender, RoutedEventArgs e) { if (number == "0") number = ""; number += 8; temp = int.Parse(number); PageTitle.Text = number; operClick = false; } private void btn9_Click(object sender, RoutedEventArgs e) { if (number == "0") number = ""; number += 9; temp = int.Parse(number); PageTitle.Text = number; operClick = false; } private void btnClear_Click(object sender, RoutedEventArgs e) { number = ""; temp = 0; equal = 0; oper = ' '; operClick = false; PageTitle.Text = "0"; } private void btnAdd_Click(object sender, RoutedEventArgs e) { if (operClick) //重複按壓運算子 { oper = '+'; //更換運算子 } else { switch (oper) //先前按壓的運算子進行運算 { case '+': equal = equal + temp; break; case '-': equal = equal - temp; break; case '*': equal = equal * temp; break; case '/': if (temp == 0) break; //處理分母為零的例外 equal = equal / temp; break; case '=': //之前按壓等於時不須做任何動作 break; default: //一開始沒有先前運算子 equal = temp; break; } number = equal.ToString(); //將等於的結果轉成字串 PageTitle.Text = number; //顯示在顯示器上 oper = '+'; //儲存這次按壓的運算元 number = ""; } operClick = true;//已按壓運算子並做完運算 } private void btnSub_Click(object sender, RoutedEventArgs e) { if (operClick) { oper = '-'; } else { switch (oper) { case '+': equal = equal + temp; break; case '-': equal = equal - temp; break; case '*': equal = equal * temp; break; case '/': if (temp == 0) break; equal = equal / temp; break; case '=': break; default: equal = temp; break; } number = equal.ToString(); PageTitle.Text = number; oper = '-'; number = ""; } operClick = true; } private void btnMulti_Click(object sender, RoutedEventArgs e) { if (operClick) { oper = '*'; } else { switch (oper) { case '+': equal = equal + temp; break; case '-': equal = equal - temp; break; case '*': equal = equal * temp; break; case '/': if (temp == 0) break; equal = equal / temp; break; case '=': break; default: equal = temp; break; } number = equal.ToString(); PageTitle.Text = number; oper = '*'; number = ""; } operClick = true; } private void btnDiv_Click(object sender, RoutedEventArgs e) { if (operClick) { oper = '/'; } else { switch (oper) { case '+': equal = equal + temp; break; case '-': equal = equal - temp; break; case '*': equal = equal * temp; break; case '/': if (temp == 0) break; equal = equal / temp; break; case '=': break; default: equal = temp; break; } number = equal.ToString(); PageTitle.Text = number; oper = '/'; number = ""; } operClick = true; } private void btnEqual_Click(object sender, RoutedEventArgs e) { switch (oper) { case '+': equal = equal + temp; break; case '-': equal = equal - temp; break; case '*': equal = equal * temp; break; case '/': if (temp == 0) break; equal = equal / temp; break; default: equal = temp; break; } number = equal.ToString(); PageTitle.Text = number; oper = '='; number = ""; } } }
顯示結果就類似這樣,至於介面玩的人就自己拉一拉吧!!!
Place your comment