![]() ![]() | introductory-examples/control-structures/control-demo.cs - A demonstration of if. | Lecture 0 - slide 8 : 25 Program 1 |
public static void IfDemo(){ int i = 0; /* Illegal: Cannot implicitly convert type 'int' to 'bool' if (i){ Console.WriteLine("i is 0"); } else { Console.WriteLine("i is not 0"); } */ /* The type of the expression i==0 is boolean */ if (i == 0){ Console.WriteLine("i is 0"); } else { Console.WriteLine("i is not 0"); } }