C# if中連續幾個條件判斷


C# if中連續幾個條件判斷

1.if (條件表達式1 && 條件表達式2)

當條件表達式1為true時

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 
 6 namespace ConsoleApplication1
 7 {
 8     class Program
 9     {
10         static void Main(string[] args)
11         {
12             int num = 1;
13             string a = "123";
14             if (a != null && (++num) > 0)
15             {
16                 a = "456";
17             }
18             Console.WriteLine(num);
19             Console.ReadKey();
20         }
21     }
22 }

2.if (條件表達式1 && 條件表達式2)

當條件表達式1為false時

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 
 6 namespace ConsoleApplication1
 7 {
 8     class Program
 9     {
10         static void Main(string[] args)
11         {
12             int num = 1;
13             string a = "123";
14             if (a == null && (++num) > 0)
15             {
16                 a = "456";
17             }
18             Console.WriteLine(num);
19             Console.ReadKey();
20         }
21     }
22 }

 

總結,在if中只有前面的條件表達式為true,才會執行后面的條件表達式。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM