Difficulty: Medium
Correct Answer: 1, 3, 5
Explanation:
Introduction / Context:
Structs in C# are value types with specific rules. Some class-like features are allowed, while others are restricted, especially regarding inheritance and constructors.
Given Data / Assumptions:
Concept / Approach:
Structs cannot be inherited; therefore, a protected accessibility level (which relies on inheritance) is not meaningful and is disallowed. Historically, user-defined parameterless constructors in structs were not allowed; the runtime provides a default parameterless constructor that zero-initializes fields. Methods are allowed in structs. Private fields and public fields are also allowed.
Step-by-Step Solution:
Verification / Alternative check:
Attempting to compile the sample as-is results in errors for protected and the explicit parameterless constructor.
Why Other Options Are Wrong:
Common Pitfalls:
Assuming class rules apply verbatim to structs; they do not due to lack of inheritance.
Final Answer:
1, 3, 5
Discussion & Comments