Poll: do you use @property semantics?

Ali Çehreli acehreli at yahoo.com
Wed Sep 14 22:38:34 UTC 2022


On 9/14/22 14:50, rikki cattermole wrote:
> 
> On 15/09/2022 9:42 AM, IGotD- wrote:
>> So @property is similar to C# get/set?
> 
> No. Getting and setting behavior via a method is not associated with 
> @property.
> 
> https://dlang.org/spec/function.html#property-functions
> 
> Works:
> 
> ```d
> struct Foo
> {
>      int data() { return m_data; } // read property
> 
>      int data(int value) { return m_data = value; } // write property
> 
>    private:
>      int m_data;
> }
> 
> void main() {
>      Foo foo;
>      foo.data = 234;
> }
> ```

I think I heard about supporting the following as well, which is 
currently missing:

     foo.data++;

An exception to that is the .length property of arrays, which is 
practically a property function with privileges. :)

Ali


More information about the Digitalmars-d mailing list