C# Language Conditional Statements If statement conditions are standard boolean expressions and values

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

The following statement

if (conditionA && conditionB && conditionC) //...

is exactly equivalent to

bool conditions = conditionA && conditionB && conditionC;
if (conditions) // ...

in other words, the conditions inside the "if" statement just form an ordinary Boolean expression.

A common mistake when writing conditional statements is to explicitly compare to true and false:

if (conditionA == true && conditionB == false && conditionC == true) // ...

This can be rewritten as

if (conditionA && !conditionB && conditionC)


Got any C# Language Question?