Boolean Expressions in C#
Learn C# (C sharp) in FREE step-by-step lessons.
Module 07: Boolean Expressions in C#
A Boolean expression is one that can be evaluated as true or false.
A Boolean expression can use relational operators such as < for less than, > for greater than, == for equal, != for not equat and the logical operators && (and) and || (or).
In this lesson we will use the If and optional else statements to decide which statements to execute.
Goals:
- Be able to use Boolean Expressions using if/else Control Structures; Values in Controls: text box, check box, radio buttons; Conditional operator:?; and switch/case
Objectives:
- Evaluate Boolean expressions;
- Use if else control structure in calculations;
- Retrieve numeric values from text box;
- Use check boxes and radio buttons in an application;
- Recognize and be able to use the conditional operator;
- Write compound Boolean expressions;
- Be able to write code using the switch/case construct.
Please study the material at each of the links below.
Microsoft Reference: Boolean expressions: C# if/else, conditional operators, OR ||, AND &&, switch/case- Boolean Expressions: A Boolean expression is one that can be evaluated to true or false
- if Statements: An if statement executes a group of statements only if certain conditions are true
- Getting Numbers from Text Box: Numeric values in a text box must be parsed.
A buffet restaurant part 1: Adding radio buttons: A restaurant charges different prices for breakfast, lunch and dinner, dicounts.
A buffet restaurant part 2: Adding code for radio buttons and check boxes: Radio buttons and check boxes have a Boolean property checked
Rats in a maze: A few problems to solve using && and ||- Left or Right?: On mouse move determine if the mouse is on left or right of form
- Top or bottom?: On mouse move determine if the mouse is on top or bottom of form
Adding the Mouse Move Event: Shows the X and Y positions when the mouse moves on the form
Scrolling: Scrolls a label across the form on the Timer event
Letter Grade: Nested if/else to find letter grade
BMI: Body Mass Index: Nested if/else to find BMI Risk- The conditional operator: ?: The ? can be used for very simple Boolean expressions in place of if/else code
- AND && And OR ||: && means AND, || means OR
Drill on Boolean: Drill to test your understanding- Middle or Side: Determine if mouse is on the side or middle
- Boolean Variables and Properties: Boolean values do not need to be compared to anything
switch/case: switch/case to show season
Glossary for boolean lessonFull Glossary