Boolean Expressions in C#
Learn C# (C sharp) in FREE step-by-step lessons.
Boolean Expressions in C#
Boolean Expressions; if/else Control Structures; Values in Controls: text box, check box, radio buttons; Conditional operator:?; switch/case
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.
In order to do this you will:
- 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: 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.
/csharp/videos/csharp-buffet1.mp4
- A buffet restaurant part 2: Adding code for radio buttons and check boxes: Radio buttons and check boxes have a Boolean property checked
/csharp/videos/csharp-buffet2.mp4
- Rats in a maze: A few problems to solve using && and ||
/videos/mousemaze.mp4
- 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
/csharp/videos/csharp-mousemove.mp4
- Scrolling: Scrolls a label across the form on the Timer event
/csharp/videos/csharp-scrolling.mp4
- Letter Grade: Nested if/else to find letter grade
/csharp/videos/csharp-nestedifelse.mp4
- BMI: Body Mass Index: Nested if/else to find BMI Risk
/csharp/videos/csharp-bmiRisk.mp4
- 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
/csharp/videos/csharp-season.mp4