Lambda syntax, etc
Kagamin
spam at here.lot
Thu Feb 5 01:32:15 PST 2009
bearophile Wrote:
> C#2 has lambdas, and C#3 adds closures and more type inferencing, so C#3+ supports the following syntaxes:
> (int i) => { return i % 3 == 1; } // C#2
> i => i % 3 == 1 // C#3
> i => { return i % 3 == 1; } // C#3, with statements too
> To define a delegate o delegate closure:
> Func<int> foo = i => { return i % 3 == 1; };
> Func<int> foo = i => i % 3 == 1;
> Func<int> bar = () => 2;
> But this isn't allowed:
> Func<void> bar = () => 2;
Yeah, C# lambdas are the killer feature. Slick, readable, C-compatible. Anders knows his job. Let's face it: delegate literals suck a little, mixins as delegates suck a lot, the former is too verbose, the latter just sucks.
More information about the Digitalmars-d
mailing list