Recall & Review
beginner
What values can a
bool type hold in C#?A
bool type in C# can hold only two values: true or false.Click to reveal answer
beginner
How does C# treat non-boolean values in conditional statements?
C# does not allow non-boolean values in conditions. For example, integers like 0 or 1 cannot be used directly as conditions; only
bool expressions are valid.Click to reveal answer
beginner
What is the default value of a
bool variable in C#?The default value of a
bool variable is false.Click to reveal answer
intermediate
Explain short-circuit evaluation with
&& and || operators in C#.In C#,
&& (AND) and || (OR) operators use short-circuit evaluation. This means the second operand is evaluated only if needed. For example, in a && b, if a is false, b is not checked.Click to reveal answer
intermediate
Can you convert a
bool to an integer directly in C#?No direct cast from
bool to int. Use Convert.ToInt32(myBool) or conditional expressions, e.g., int x = myBool ? 1 : 0;.Click to reveal answer
Which of the following is a valid
bool value in C#?✗ Incorrect
Only true and false are valid bool values in C#.
What happens if you try to use an integer directly in an
if condition in C#?✗ Incorrect
C# requires a bool expression in conditions; integers cannot be used directly.
What is the default value of a
bool field in a class if not initialized?✗ Incorrect
Boolean fields default to false if not explicitly initialized.
In the expression
a && b, when is b evaluated?✗ Incorrect
b is evaluated only if a is true because of short-circuit evaluation.
How can you convert a
bool variable flag to an integer 1 or 0?✗ Incorrect
Both the conditional (ternary) operator and Convert.ToInt32(flag) safely convert bool to int (1 for true, 0 for false). Direct casting does not work.
Describe how C# handles boolean values and their use in conditional statements.
Think about what values are allowed and how conditions work.
You got /3 concepts.
Explain short-circuit evaluation in C# boolean operators and why it matters.
Consider when the second part of a condition runs.
You got /3 concepts.