Which keyword should you use?

You have a class with a property.
You need to ensure that consumers of the class can write to the value of the property.
Which keyword should you use?

You have a class with a property.
You need to ensure that consumers of the class can write to the value of the property.
Which keyword should you use?

A.
value

B.
add

C.
get

D.
set



Leave a Reply 6

Your email address will not be published. Required fields are marked *


Christian Zalto

Christian Zalto

I would have answered “D”, keyword “set”. But of course you could use the keyword “value” in a set-accessor, so it’s not completely wrong.

R

R

Should be D. 🙂

AydinNasirzadeh

AydinNasirzadeh

I think there is nothing wrong with the answer this site offers. SET and VALUE are two things. Here the answer VALUE is much more appropriate.

AydinNasirzadeh

AydinNasirzadeh

The SET keyword defines an accessor method in a property or indexer that assigns the value of the property or the indexer element. However, the contextual keyword VALUE is used in the set accessor in ordinary property declarations. It is similar to an input parameter on a method. The word VALUE references the value that client code is attempting to assign to the property.