Difficulty: Easy
Correct Answer: Sample m = new Sample(); m.Length = 10;
Explanation:
Introduction / Context:
A write-only property exposes only a set accessor and no get accessor. This question checks whether you can distinguish valid usage of such a property (assignment) from invalid usage (reading the value).
Given Data / Assumptions:
Concept / Approach:
You can assign to a write-only property on an instance, for example m.Length = 10;. Any attempt to read it (store into a variable, use on the right-hand side, or print it) will not compile because there is no get accessor. Static references like Sample.Length are also invalid unless the property is static (not stated).
Step-by-Step Solution:
Verification / Alternative check:
Define public int Length { set { ... } } and compile; only direct assignments are legal.
Why Other Options Are Wrong:
Common Pitfalls:
Confusing a write-only instance property with a static property; or assuming you can read a value after setting it.
Final Answer:
Sample m = new Sample(); m.Length = 10;
Discussion & Comments