Difficulty: Easy
Correct Answer: Declare accountNo with both get and set accessors.
Explanation:
Introduction / Context:
The sample code performs both a write and a read: acc.accountNo = 10; and Console.WriteLine(acc.accountNo);. Therefore, the property must support assignment and retrieval. This is a standard read–write property in C#.
Given Data / Assumptions:
Concept / Approach:
A C# property that can be both read and assigned must include a get accessor (to return the value) and a set accessor (to accept a value via the implicit parameter value). Omitting either accessor would disable the corresponding operation.
Step-by-Step Solution:
Verification / Alternative check:
Compile with both accessors present and observe that both statements are valid. Remove get or set and see the relevant statement fail.
Why Other Options Are Wrong:
Common Pitfalls:
Confusing access modifiers (public/private) with accessors (get/set). You can also fine-tune with private set if external code should not assign.
Final Answer:
Declare accountNo with both get and set accessors.
Discussion & Comments