Bird
0
0

Which statement about init-only setters is true?

easy🧠 Conceptual Q2 of 15
C Sharp (C#) - Properties and Encapsulation
Which statement about init-only setters is true?
AThey can be assigned anywhere in the class after construction.
BThey prevent the property from being read.
CThey behave exactly like traditional setters.
DThey can only be assigned in the constructor or object initializer.
Step-by-Step Solution
Solution:
  1. Step 1: Recall init-only setter assignment rules

    Init-only setters allow assignment only during construction or object initialization.
  2. Step 2: Evaluate each option

    They can only be assigned in the constructor or object initializer. matches the rule; A and C are false because they allow later assignment; D is false because properties remain readable.
  3. Final Answer:

    They can only be assigned in the constructor or object initializer. -> Option D
  4. Quick Check:

    Init-only assignment = constructor or initializer only [OK]
Quick Trick: Init-only = assign once during creation, not later [OK]
Common Mistakes:
MISTAKES
  • Assuming init-only setters allow changes anytime
  • Confusing init-only with readonly properties
  • Thinking init-only disables reading property

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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