Back to Browse

C# - Part 11 - If | Else If | Else - Tutorial For Beginners

59 views
Mar 5, 2024
17:08

In this video we will be learning about if, else if, else in C# Timestamps -- 00:00 Intro 00:50 Demo - If, Else If, Else 07:38 Logical AND 10:04 Logical OR 11:55 Simple Program 17:00 Outro Imagine you're setting up rules in your program. if, else if, and else statements are like those rules, deciding what happens next based on certain conditions. if statement: This is the first rule checker. If a specific condition is true, like "you're 18 or older," a particular action happens, like granting access. else if statement (optional): This is like another chance. If the first condition isn't met (you're not 18 yet), this checks another condition. Maybe it says "you're with a parent," and if that's true, you still get access. You can have multiple else if statements like a chain of backup rules. else statement (optional): This is the final catch-all. If none of the previous conditions were true (you're not 18 and not with a parent), this decides what happens next. Maybe it says "access denied." There can only be one else statement, and the program checks the conditions from top to bottom. It's like following a set of instructions in order until it finds the one that applies. && (Conditional AND): Short-circuit evaluation: If the first operand evaluates to false, the second operand is not evaluated. This optimizes performance by avoiding unnecessary calculations. Result: Returns true only if both operands are true, otherwise returns false. & (Bitwise AND): No short-circuit evaluation: Both operands are always evaluated, regardless of the value of the first operand. Result: Performs a bit-by-bit AND operation, resulting in a new value where only the corresponding bits that are 1 in both operands become 1, and the rest become 0. || (Conditional OR): Short-circuit evaluation: If the first operand evaluates to true, the second operand is not evaluated. This optimizes performance by avoiding unnecessary calculations. Result: Returns true if at least one operand is true, otherwise returns false. | (Bitwise OR): No short-circuit evaluation: Both operands are always evaluated, regardless of the value of the first operand. Result: Performs a bit-by-bit OR operation, resulting in a new value where any corresponding bit that is 1 in either operand (or both) becomes 1, and the rest become 0.

Download

0 formats

No download links available.

C# - Part 11 - If | Else If | Else - Tutorial For Beginners | NatokHD