Demonstrations of if. | Lecture 2 - slide 14 : 43 Program 2 |
/* Right, Wrong */ using System; class IfDemo { public static void Main(){ int i = 0; /* if (i){ Console.WriteLine("i is regarded as true"); } else { Console.WriteLine("i is regarded as false"); } */ if (i != 0){ Console.WriteLine("i is not 0"); } else { Console.WriteLine("i is 0"); } } } | Illegal: Cannot implicitly convert type 'int' to 'bool' The type of the expression i != 0 is boolean |