Properties

Nick Sabalausky a at a.a
Thu Jan 8 10:45:27 PST 2009


"bearophile" <bearophileHUGS at lycos.com> wrote in message 
news:gk5grh$2o8i$1 at digitalmars.com...
> 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).
>

Something like this:

public property int var
{
    get { return property; }
    set { property = $; }
}

Or something like this:

public property int foo
{
    get { return $; }
    set { $ = $new; }
}

> Let's see if Walter likes all this.
>
> Bye,
> bearophile 





More information about the Digitalmars-d mailing list