- Learn C# in 7 days
- Gaurav Aroraa
- 93字
- 2021-07-08 09:51:28
The if..else statement
In this if statement followed by else and the else block execute in case evaluation of if block is false. This is a simple example:
private static void IfElseStatementExample() { WriteLine("if statement example."); Write("Enter character:"); char inputChar = Convert.ToChar(ReadLine()); char[] vowels = {'a', 'e', 'i', 'o', 'u'}; if (vowels.Contains(char.ToLower(inputChar))) WriteLine($"Character '{inputChar}' is a vowel."); else WriteLine($"Character '{inputChar}' is a consonent."); }
In the preceding code snippet, we are using else followed by the if statement. When the if statement evaluates to false, then the else block code will be executed.
推薦閱讀
- HornetQ Messaging Developer’s Guide
- 碼上行動:零基礎(chǔ)學(xué)會Python編程(ChatGPT版)
- 我的第一本算法書
- C++程序設(shè)計基礎(chǔ)教程
- Drupal 8 Configuration Management
- HTML5從入門到精通 (第2版)
- 數(shù)據(jù)結(jié)構(gòu)案例教程(C/C++版)
- 一本書講透Java線程:原理與實踐
- Python函數(shù)式編程(第2版)
- STM8實戰(zhàn)
- 超好玩的Scratch 3.5少兒編程
- 零基礎(chǔ)學(xué)Java第2版
- Mastering Bootstrap 4
- Mapping with ArcGIS Pro
- Apache Solr for Indexing Data