Difficulty: Easy
Correct Answer: 1, 3
Explanation:
Introduction / Context:The exercise assesses valid C# initialization forms when you want both variables i and j to be set to 10.
Given Data / Assumptions:
Concept / Approach:Legal, clear initializations are either two separate statements or a compound declaration assigning both. The colon operator in (2) is invalid in this context. In (4) only j is initialized. In (5) chained assignment requires j to already exist in scope.
Step-by-Step Solution:
(1) Valid: both i and j become 10. (2) Invalid: uses ":" which is not assignment. (3) Valid: both initialized in one statement. (4) Not meeting the requirement: i is uninitialized. (5) Invalid in a declaration: j is not declared before use.Verification / Alternative check:Compile examples (1) and (3) — both succeed; (2), (4), (5) either fail or don’t meet the “both 10” requirement.
Why Other Options Are Wrong:They include invalid constructs or statements that fail to set both variables to 10.
Common Pitfalls:Believing chained assignment works inside the same declaration for multiple new identifiers.
Final Answer:1, 3
Discussion & Comments