# C# ``` //int double decimal跟Log int a = 50; int b = a++; int c = a/b; c = c%b; Console.WriteLine($"C={c}"); Console.WriteLine($"max={int.MaxValue},min={int.MinValue}"); int max = int.MaxValue; a = max; Console.WriteLine($"a={a}"); double D = 29; double F = D++; double G = D / F; Console.WriteLine(G); double Z = 1.0/3.0; Console.WriteLine(Z); decimal O = 1.3m; decimal P = O++; Console.WriteLine(O/P); double PI = Math.PI; double Ans = 2.50*2.50*PI; Console.WriteLine(Ans); ``` ``` using System; using System.Threading; namespace 練習 { class Program { static void Main() { { 一維陣列(); } } static void While迴圈() //如果變數≠0就減到0為止 { int 倒數 = 10; { while (倒數 != 0) { Console.WriteLine($"現在是{倒數}"); 倒數--; Thread.Sleep(1000); } } } static void Do迴圈() // 執行勾勾true如果勾勾是false { bool 勾勾 = false; do { 勾勾 = true; Console.WriteLine(勾勾); } while (勾勾 == false); } static void For迴圈() //變數、條件、動作可以寫在一起(但好像動作只能寫一行剩下的還是要寫到下面去) { for (int 居然可以寫在裡面 = 0; 居然可以寫在裡面 < 10; Console.WriteLine(居然可以寫在裡面) ) { 居然可以寫在裡面++; } } static void 綜合() //分支與迴圈 { int 被除數 = 1; int 除數 = 3; int 總和 = 0; while (被除數 <= 20) { if (被除數 % 除數 == 0) { 總和 = 總和 + 被除數; Console.WriteLine($"現在到{被除數},可被{除數}整除,加進總和中,目前總和為{總和}"); 被除數 ++; } else if (被除數%除數 != 0) { Console.WriteLine($"現在到{被除數},無法被{除數}整除,不加進總和,目前總和為{總和}"); 被除數++; } } //這個比較短(只是沒有直播) /*int sum = 0; for (int number = 1; number < 21; number++) { if (number % 3 == 0) { sum = sum + number; } }*/ } static void 一維陣列() { int[] a = new int[10]; for (int b = 0; b < a.Length; b++) { a[b] = b + b; Console.WriteLine($"{b}相加為{a[b]}"); a[b] = b * b; Console.WriteLine($"{b}相乘為{a[b]}"); } } } } ``` ``` static void 簡單互動應用() { { Console.WriteLine("say 'dododo' plz"); string Ans = Console.ReadLine(); switch (Ans) { case "dododo": Console.WriteLine("Nice :D"); break; default : Console.WriteLine("X"); Console.WriteLine("接下來該怎麼做?"); Console.WriteLine("輸入1 重來"); Console.WriteLine("輸入2 結束"); String Event = Console.ReadLine(); switch (Event) { case "1": 簡單互動應用(); break; case "2": Console.WriteLine("bye~"); return; } break; } } } ``` ``` using OpenQA.Selenium; using OpenQA.Selenium.Chrome; using System; using System.Threading; using System.Windows.Forms; namespace 模擬登入 { class Program { // static void Main(string[] args) { 登入(); } static void 登入() { Console.WriteLine("輸入帳號"); string 帳號 = Console.ReadLine(); Console.WriteLine("輸入密碼"); string 密碼 = Console.ReadLine(); IWebDriver driver = new ChromeDriver(); //開網頁 driver.Navigate().GoToUrl("https://agent.mearhh.com/login"); //防卡頓:確定畫面跑出 資料才往下執行 driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10000); //帳號 IWebElement inputAccount = driver.FindElement(By.Name("account"));//搜索輸入框的name // Thread.Sleep(500); inputAccount.Clear();//預防cookie先清除內容 // Thread.Sleep(500); inputAccount.SendKeys(帳號);//輸入 // Thread.Sleep(500); //密碼 IWebElement inputPassword = driver.FindElement(By.Name("password")); inputPassword.Clear(); // Thread.Sleep(500); inputPassword.SendKeys(密碼); // Thread.Sleep(500); //登入 IWebElement submitButton = driver.FindElement(By.XPath("/html/body/div[2]/form/div[3]/button"));//搜索登入鍵路徑 // Thread.Sleep(500); submitButton.Click();//鍵入 // driver.Navigate().GoToUrl("https://agent.mearhh.com/profile"); SendKeys.SendWait("{F5}"); // driver.Quit();//over } } } ``` ``` static void Foreach迴圈() { { int[] BankBook = new int[5] { 1000, 2000, 3000, 4000, 5000 }; foreach (int money in BankBook) { Console.WriteLine("此存摺剩餘:" + money); } } } ``` ``` using System; using System.Collections.Generic; using System.Linq; using System.Text; //using System.Threading.Tasks; using HtmlAgilityPack; using System.Net; using System.IO; namespace test { class Program { static void Main(string[] args) { WebClient url = new WebClient(); //指定來源網頁 MemoryStream ms = new MemoryStream(url.DownloadData("http://www.coolpc.com.tw/evaluate.php"));//將網頁來源資料暫存到記憶體內 HtmlDocument doc = new HtmlDocument();// 使用預設編碼讀入 HTML doc.Load(ms, Encoding.Default); if (doc != null) { var list_type = new List<string>(); HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes("//select[@name='n4']//optgroup"); foreach (HtmlNode node in nodes) { var type = node.Attributes["label"].Value; list_type.Add(type); } List<string> list_name = doc.DocumentNode.SelectSingleNode("//select[@name='n4']").InnerText.Split('\n').ToList(); //刪除不必要的非商品選項 list_name.RemoveRange(0, 3); list_name.RemoveAt(list_name.Count - 1); var models = new List<Product>(); int number = 0; for (int i = 0; i < list_name.Count; i++) { string type = list_type[number]; string name = list_name[i]; if (name == "") { number++; } else { models.Add(new Product() { type = type, name = name }); Console.WriteLine("類型:{0} ,", type); Console.WriteLine("名稱:{0}", name); } } Console.ReadLine(); } } } class Product { public string type { get; set; } public string name { get; set; } } } ``` ``` //unchecked、checked try { unchecked //un不檢查 但會倒扣 check會直接回傳溢位 { int A = int.MinValue; int B = 1; int C = A - B; Console.WriteLine($"{A},{B},{C}"); } } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.ReadLine(); ``` ``` ``` ``` ``` ```