Properties

bearophile bearophileHUGS at lycos.com
Thu Jan 8 10:32:17 PST 2009


Chad J:
> public property int var
> {
>     get { return var; }
>     set { var = $; }
> }
> 
> public property int foo
> {
>     get { return foo; }
>     set { foo = $; }
> }

I think I have suggested something similar, time ago.

The default situations you have shown may enjoy an even shorter syntax, for example:
public property int var { get set }

That can also become the following when you want only a getter or setter:
public property int var { get }
Or:
public property int var { set }


(I don't like all those repeated "foo"/"var", it's not much DRY. But at the moment I see no better solution, that works well for nested classes/structs too).

Let's see if Walter likes all this.

Bye,
bearophile



More information about the Digitalmars-d mailing list