flask
flask
CC#
Created by flask on 3/3/2024 in #help
✅ **Hello, could you help me understand `&`, `&&`, `|`, `||` in C# with this code example:**
int a = 4, b = 3, c = 2, d = 1;

if (a / b > 1 & c - d < 1 | a % 2 == 0)
label1.Text = "everything's cool";
else
label1.Text = "everything's bad";
int a = 4, b = 3, c = 2, d = 1;

if (a / b > 1 & c - d < 1 | a % 2 == 0)
label1.Text = "everything's cool";
else
label1.Text = "everything's bad";
Why does the if condition execute when a/b>1 is false? The ampersand & upon encountering the first false, immediately triggers else, and evaluates the rest of the expression in the background (right??). Its further calculation of other expressions after the & should not change the outcome (?), as it is not the OR operator |. Why do we then end up with 'everything's cool'?"
24 replies