On 04/29/2012 10:03 PM, Alex Rønne Petersen wrote:
On 28-04-2012 23:41, Timon Gehr wrote:

As I understand it, the 'agreed upon' design is that

@property int foo() { return x; }
@property void foo(int v) { x = v; }

Would be completely equivalent to C#:

int foo { set{ x = value; }; get{ return x; } }

Nope.

First of all, you'd have to declare the setter like this in D:

@property int foo(int v) { return x = v; }

so that you can write:

int v = obj.foo = 1; // valid C#

Next up is the issue of op-assign operations. In D, you can't do:

obj.foo += 1;
obj.foo++;

while in C#, you can (it results in a get -> add 1 -> set and get -> inc
-> set, etc).


I didn't say this was how it worked in the current compiler implementation. But I may be wrong on what is the design because I didn't take part in that discussion.

Notably, read-update operations now work on the built-in length property of arrays. I don't think there is any justification for not implementing this for properties.

Reply via email to