properties - Why not the set/get syntax?

John C johnch_atms at hotmail.com
Sat Apr 1 06:19:17 PST 2006


"Cris" <central_p at hotmail.com> wrote in message 
news:e0m0lc$2slj$1 at digitaldaemon.com...
> Cris wrote:
>> John C wrote:
>>> "Cris" <central_p at hotmail.com> wrote in message 
>>> news:e0lr0p$2n17$1 at digitaldaemon.com...
>>>> How would you implement a  write only property?
>>>
>>> Implement only the setter.
>>
>> I mean a property that you can write but you cannot read. You can do that 
>> in C#. Is it possible in D too?
>
>
> Oh, yes it's possible:
>
> class Bicycle
> {
>     this()
>     {
>         gear = 1;
>     }
>
>     int currentGear;
>
>     int gear()
>     {
>         return currentGear;
>     }
>
>     void gear(int value)
>     {
>         currentGear = value;
>     }
> }

But Bicycle.gear can be both read and written. I showed you in another reply 
how to do a write-only property.

>
> So it means that there is absolyutely no difference between properties and 
> functions in D? Perhaps the notion "property" is a little bit confusing in 
> this case.

This is why people keep suggesting an alternative syntax so that the 
compiler distinguishes between them. But it works most of the time, unless 
you're using it with auto type inference (in which case you need to use the 
parentheses). 





More information about the Digitalmars-d mailing list