C# Programming - Properties - Discussion

Discussion Forum : Properties - General Questions (Q.No. 3)
A Student class has a property called rollNo and stu is a reference to a Student object and we want the statement stu.RollNo = 28 to fail. Which of the following options will ensure this functionality?
Declare rollNo property with both get and set accessors.
Declare rollNo property with only set accessor.
Declare rollNo property with get, set and normal accessors.
Declare rollNo property with only get accessor.
None of the above
Answer: Option
No answer description is available. Let's discuss.
1 comments Page 1 of 1.

Ram said:   1 decade ago
In property, get accessor implies read only and set accessor implies write only. So here we want to stop setting a value. Remove set accessor.

Post your comments here:

Your comments will be displayed after verification.