anonymous function/delegate usage

BCS none at anon.com
Thu Nov 12 20:06:54 PST 2009


Hello Sam,

> Don Wrote:
> 
>> You need to call the delegate you've made.
>> 
> I missed this key point.
> 
> So to summary:
> int a=1;
> int b=2;
> 1.nested function;
> 2.int c=(int a,int b){return a+b;}(a,b);
> 3.int c=(int,int){return a+b;}(a,b);
> 4.int c=(){return a+b;}();
> 5.int c={return a+b;}();
> How come the last one is legal?

If the function has no args the first () can be dropped.
If the return type can be inferred, that can be dropped.
Nested functions can access vars in the outer function.

> 
> Thank you all for all your help!
> 




More information about the Digitalmars-d-learn mailing list