C# Programming - Properties - Discussion

Discussion Forum : Properties - General Questions (Q.No. 2)
2.
Which of the following statements is correct about properties used in C#.NET?
A property can simultaneously be read only or write only.
A property can be either read only or write only.
A write only property will have only get accessor.
A write only property will always return a value.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
5 comments Page 1 of 1.

Rutuja said:   9 years ago
The code block for the get accessor is executed when the property is read; the code block for the set accessor is executed when the property is assigned a new value.

A property without a set accessor is considered read-only. A property without a get accessor is considered write-only. A property that has both accessors is read-write.

Ahmedkorany said:   9 years ago
B can't be true A is true and maybe D.

Billal said:   1 decade ago
I think the answer should be A because we can have the prop with getter/setter at the same time.

EliasHdez said:   1 decade ago
From the C# Language Specification:
"A property is declared like a field, except that the declaration ends with a get accessor and/or a set accessor written between the delimiters { and } instead of ending in a semicolon. A property that has both a get accessor and a set accessor is a read-write property, a property that has only a get accessor is a read-only property, and a property that has only a set accessor is a write-only property."

Sundar said:   1 decade ago
A property is classified according to the accessors used as follows:

A property with a get accessor only is called a read-only property. You cannot assign a value to a read-only property.

A property with a set accessor only is called a write-only property. You cannot reference a write-only property except as a target of an assignment.

A property with both get and set accessors is a read-write property.

Post your comments here:

Your comments will be displayed after verification.