Difficulty: Easy
Correct Answer: A property can be either read only or write only.
Explanation:
Introduction / Context:
Properties are a core C# feature that encapsulate access to fields. The presence of get and/or set accessors determines whether a property is readable, writable, or both. This question asks for the correct generic statement about property capabilities.
Given Data / Assumptions:
Concept / Approach:
A property can be read-only (get; no set;), write-only (set; no get;), or read–write (both get and set). A write-only property does not return a value; it simply accepts a value in its set accessor via the implicit parameter value. Any statement claiming a property is simultaneously read only and write only is self-contradictory.
Step-by-Step Solution:
Verification / Alternative check:
Code examples: public int Id { get; } (read-only), public int Secret { set { ... } } (write-only), public int Count { get; set; } (read–write).
Why Other Options Are Wrong:
Common Pitfalls:
Assuming write-only properties are common; they are rare because callers cannot read back a value. Use scenarios include sensitive data, logging, or command-like APIs.
Final Answer:
A property can be either read only or write only.
Discussion & Comments