C#C
C#2y ago
flask

✅ **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";


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'?"
Was this page helpful?
✅ **Hello, could you help me understand `&`, `&&`, `|`, `||` in C# with this code example:** - C#