Difficulty: Medium
Correct Answer: 2, 3
Explanation:
Introduction / Context:
This question checks nuanced C# rules for switch, foreach, and for statements.
Given Data / Assumptions:
Concept / Approach:
Classic C# switch does not use bool. It does support char, string, and enum. Declaring variables directly under a case usually requires braces to create scope. foreach is read-only in intent; modifying the collection during enumeration is discouraged. In C#, for(;;) is allowed, so all three expressions are optional.
Step-by-Step Solution:
Verification / Alternative check:
Language specifications and compiler behavior confirm items 2 and 3 only.
Why Other Options Are Wrong:
Common Pitfalls:
Forgetting to use braces when declaring variables within case sections.
Final Answer:
2, 3
Discussion & Comments