Bird
0
0

Why might a developer prefer properties over public fields in C#?

hard🧠 Conceptual Q10 of 15
C Sharp (C#) - Properties and Encapsulation
Why might a developer prefer properties over public fields in C#?
AProperties use less CPU time than fields.
BProperties cannot be inherited, unlike fields.
CProperties provide encapsulation and allow adding logic on access.
DProperties automatically serialize without extra code.
Step-by-Step Solution
Solution:
  1. Step 1: Understand encapsulation benefits

    Properties allow controlling how data is accessed or modified, adding validation or logic.
  2. Step 2: Evaluate options

    Only Properties provide encapsulation and allow adding logic on access. correctly states that properties provide encapsulation and logic on access.
  3. Final Answer:

    Properties provide encapsulation and allow adding logic on access. -> Option C
  4. Quick Check:

    Properties = Encapsulation + logic [OK]
Quick Trick: Properties enable control and validation on data access [OK]
Common Mistakes:
MISTAKES
  • Assuming properties are faster than fields
  • Thinking properties cannot be inherited
  • Believing properties auto-serialize always

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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