Confusion with anonymous functions and method overloads
ag0aep6g via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat May 21 07:58:01 PDT 2016
On 05/21/2016 04:39 PM, pineapple wrote:
> But I don't understand why. Could someone clarify the difference between
> the two?
Common mistake, because other languages (e.g. C#) use similar but
different syntax.
The `foo => bar` syntax doesn't use braces. When you add braces around
bar, that's a delegate that runs bar when called.
I.e., this:
foo => bar
is equivalent to this:
(foo) {return bar;}
And this:
foo => {bar;}
is equivalent to this:
(foo) {return () {bar;};}
More information about the Digitalmars-d-learn
mailing list