anonymous function/deleget usage

Steven Schveighoffer schveiguy at yahoo.com
Thu Nov 12 07:40:34 PST 2009


On Thu, 12 Nov 2009 10:21:44 -0500, Don <nospam at nospam.com> wrote:

> Sam Hu wrote:
>> How can I reach something like below code:
>>  int a=1;
>> int b=2;
>> int c=(int a,int b){
>>    return a+b;}
>> writefln("Result:%d",c);
>>  Thanks in advance.
>
> You need to call the delegate you've made.
>
> int a=1;
> int b=2;
> int c=(int a,int b){
>     return a+b;}(a,b);
> writefln("Result:%d",c);}

Also, don't forget you can refer to variables in the enclosing function:

int c = (){return a + b;}();

-Steve


More information about the Digitalmars-d-learn mailing list