C# 學習筆記 part 8 教你使用 if 單層判斷,教你使用 if else if else 多層判斷

C# 入門 教學 8 教你使用 if 單層判斷式,教你使用 if else if else 多層判斷式

C# 或其他程式語言,都會學到 if 判斷式

if statements 是翻 if 陳述式,或是 if 語句

額...好吧,反正知道意思就好,是用來判斷東西,是否繼續向下執行...

大致上,會用在

1、字串比對是否一樣

2、變數內的值,比大小

3、布林,做旗標,或當開關用

如果你未安裝 Visual Studio 開發套件,參考 C# 學習,教你下載安裝 Visual Studio Community

卡在命名問題,參考 C# 學習 part 3 卡在第一關,命名問題...只能借助 Goole 翻譯

回顧上一篇,參考 創建 Windows Forms 窗體,使用 Windows Forms 窗體


教你使用 if 單層判斷

IfStatements.cs 內容




Program.cs 內容

定義 BigSmall 物件,那串的意思,可參考 C# 學習筆記 part 6 創建 class 物件,使用 class 物件 文章底部的筆記




結果




如果判斷,只有是否2種,則用 if else 單層判斷

上述代碼,可以改寫成







教你使用 if else if else 多層判斷

IfStatements.cs 內容




Program.cs 內容




結果







複習之前,說過的專有名詞




參數,有的地方叫引數,它的作用是間接傳值




本篇,要了解的專有名詞

比較運算子,比對運算子,匹配運算子

等號比較運算子 (C# 參考)

https://docs.microsoft.com/zh-tw/dotnet/csharp/language-reference/operators/equality-operators

等號比較運算子 ==




不等比較運算子 !=




比較運算子 (C#參考)

https://docs.microsoft.com/zh-tw/dotnet/csharp/language-reference/operators/comparison-operators




C# 學習筆記

if statements 是翻 if 陳述式,或是 if 語句,指的是 if 那一整串

if 後面 () 小括號內,可以叫條件式

條件式中間的那些符號,叫做運算子






此篇文章之圖文教學,如果還不太明白,請至下方連結,查看 youtube 視頻解說

視頻解說之第一部分 https://www.youtube.com/watch?v=2f_k1cWY7LE

謝謝大家,抽空觀看,files備份檔名 csharp00008


後續文章 C# part 9 教你使用 if else if else 多層判斷,配合 Windows Forms 窗體


C# tutorial 8 Show you how to use if statements

沒有留言:

張貼留言

由於經常被灌水, 所以您再發表留言之後, 需要耐心的等待博客主之審核, 於審核過後才會公開您的留言, 因此請您不要重複的留言, 謝謝您的留言
Hello my friend, I have no money, My blog is super chill, Please do not screw me in the replies at the bottom of the article, thank you very much