Re: What is a property?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi Peter,

> It is also possible via getter and setter methods. What exact benefit does
> a "property" give us over getter and setter methods?

Simply look at this Example and decide yourselve, wich is more readable:

oldText = control.get_Text();
control.get_Text(newText);

vs.

oldText = control.Text;
constrol.Text = newText;

Christof

"Peter Kirk" <pk@xxxxxxxxxxxxxxxxxx> schrieb im Newsbeitrag
news:u1GkVPJgFHA.3448@xxxxxxxxxxxxxxxxxxxxxxx
> "Prakash Prabhu K" <PrakashPrabhuK@xxxxxxxxxxxxxxxxxxxxxxxxx> skrev i en
> meddelelse news:390C9AB7-86F2-4D6D-9E00-21B1AEDEDFE2@xxxxxxxxxxxxxxxx
>> Hi Peter,
>>
>> we can tell properties are smart fields (Class members) in C#. Public
>> fields
>> in the class would give complete access to field from other classes. So
>> it is
>> not possible to give read-only or write only access to public fields.
>> This is
>> possible through properties.
>>
>> Properties can give read only, write only or read right access to
>> fields.
>> This also allow us to add extra business logic to fields.
>
> It is also possible via getter and setter methods. What exact benefit does
> a "property" give us over getter and setter methods?
>
>
>


.



Relevant Pages