C # consecutive conditions in if,
C # Continuous Condition judgment in if
1. if (condition expression 1 & condition expression 2)
When condition expression 1 is 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 (condition expression 1 & condition expression 2)
When conditional expression 1 is 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 }
In summary, only the preceding conditional expression true in if executes the following conditional expression.