A few lessons so far dealt with conditional processing, displaying a result when a condition is true, and another when it is false. When working with conditional processing, it is important to understand the representation of True and False values in C#.
C# checks by default a conditional statement if it returns a true value. Many inexperienced programmers write their test conditions as follows:
1 |
if (expression != false) //check if the expression is True |
Since the program checks the default value as being True, you can write you test conditions by simply placing the condition in parenthesis:
1 |
if (expression) |
When the expression is evaluated as a value different than False, C# executes the instructions that follows immediately after the condition. When it is evaluated as False, C# will simply ignore the instructions that follow after the condition.
The concepts explained in this lesson are also shown visually as part of the following video: