C# Programming - Properties - Discussion

Discussion :: Properties - General Questions (Q.No.2)

2. 

Which of the following statements is correct about properties used in C#.NET?

[A]. A property can simultaneously be read only or write only.
[B]. A property can be either read only or write only.
[C]. A write only property will have only get accessor.
[D]. A write only property will always return a value.

Answer: Option B

Explanation:

No answer description available for this question.

Sundar said: (Sep 22, 2011)  
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.

Eliashdez said: (Feb 8, 2013)  
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."

Billal said: (Jan 31, 2014)  
I think the answer should be A because we can have the prop with getter/setter at the same time.

Ahmedkorany said: (Jul 13, 2015)  
B can't be true A is true and maybe D.

Rutuja said: (Oct 23, 2015)  
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.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.