Bird
0
0

Why might a developer choose to use a write-only property instead of a public field in C#?

hard🧠 Conceptual Q10 of 15
C Sharp (C#) - Properties and Encapsulation

Why might a developer choose to use a write-only property instead of a public field in C#?

ATo control how data is set and prevent reading sensitive info
BTo allow both reading and writing freely
CTo make the property read-only
DTo improve performance by avoiding methods
Step-by-Step Solution
Solution:
  1. Step 1: Understand write-only property purpose

    It allows setting data while hiding it from being read externally.
  2. Step 2: Compare with public fields

    Public fields allow direct read and write, no control or hiding.
  3. Final Answer:

    To control how data is set and prevent reading sensitive info -> Option A
  4. Quick Check:

    Write-only properties protect sensitive data by hiding reads [OK]
Quick Trick: Write-only properties protect sensitive data from being read [OK]
Common Mistakes:
MISTAKES
  • Thinking write-only allows reading
  • Confusing with read-only properties
  • Assuming performance benefit

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Sharp (C#) Quizzes