Difficulty: Easy
Correct Answer: 1, 2
Explanation:
Introduction / Context:
Value types (structs) in C#.NET support a rich set of members, though they have some limitations compared to classes. This item asks which features are permitted in a struct definition.
Given Data / Assumptions:
Concept / Approach:
Structs can contain fields, properties, methods, operators, events, indexers, and constructors. They cannot declare a protected member because structs cannot be inherited. They can define constructors, but historically user-defined parameterless constructors were disallowed until newer language versions; parameterized constructors are always allowed. Structs can include constants (const members).
Step-by-Step Solution:
Verification / Alternative check:
Create a sample struct with a property, a parameterized constructor, a method, and a const; it compiles. Attempt to mark a member protected; the compiler rejects it.
Why Other Options Are Wrong:
Common Pitfalls:
Assuming structs are too restricted; they are feature-rich but simply non-inheritable.
Final Answer:
1, 2
Discussion & Comments