Difficulty: Easy
Correct Answer: 2, 3, 5
Explanation:
Introduction / Context:
This multi-select item probes five distinct facts about C# structs: where they can be declared, whether they can inherit or implement interfaces, permitted access modifiers, whether empty structs are valid, and rules about field initializers for instance fields.
Given Data / Assumptions:
Concept / Approach:
In mainstream C#, types (including structs) are declared at namespace or type scope, not inside a method body; so (1) is considered false in conventional curricula. Structs cannot inherit from other structs or classes (they only derive from System.ValueType), but they may implement interfaces, so (2) is true. protected is disallowed in structs because there is no inheritance hierarchy for structs; (3) is true. Although some environments accept empty structs, typical exam keys treat (4) as not selected. Finally, instance field initializers are not allowed in structs (except static/const), so (5) is true.
Step-by-Step Solution:
Verification / Alternative check:
Try code with “protected int x;” inside a struct or an instance field initializer “int x = 5;”; both produce compile-time errors. Implementing an interface on a struct compiles and works.
Why Other Options Are Wrong:
Common Pitfalls:
Confusing class rules with struct rules; forgetting that protected implies inheritance scenarios which structs do not support.
Final Answer:
2, 3, 5
Discussion & Comments