Which of the following statements is correct regarding C# selection statements?
-
AIt is not possible to extend the if statement for multiple conditions using else-if.
-
BThe switch statement may contain duplicate case values.
-
CA jump statement such as break is required after each case block, excluding the last block if it is default.
-
DThe if statement selects a statement for execution based on the value of a Boolean expression.
-
EC# always supports implicit fall-through from one case label to another.
Answer
Correct Answer: The if statement selects a statement for execution based on the value of a Boolean expression.
Explanation
Introduction / Context:This question tests knowledge of how C# selection statements behave, particularly if/else and switch.
Given Data / Assumptions:
- We evaluate five independent statements and must pick one correct statement.
Concept / Approach:In C#, if evaluates a Boolean expression and selects a branch accordingly. switch requires unique case values and, unlike C, does not allow implicit fall-through between non-empty cases.
Step-by-Step Solution:
Option A: False — else-if chains are standard for multiple conditions.Option B: False — duplicate case values cause a compile error.Option C: Partially accurate but unnecessary nuance; the safe unequivocal truth is D.Option D: True — if chooses a path based on a Boolean expression.Option E: False — C# forbids implicit fall-through except into empty cases.Verification / Alternative check:Any C# specification summary confirms D; B and E are explicitly disallowed; A contradicts common usage.
Why Other Options Are Wrong:
- A: else-if is the normal extension.
- B: Duplicate case values are illegal.
- C: Even the last default block typically uses break or returns; D is the clearly correct general statement.
- E: No implicit fall-through in non-empty cases.
Common Pitfalls:Confusing C# switch rules with C/C++ behavior.
Final Answer:The if statement selects a statement for execution based on the value of a Boolean expression.