[Israel.pm] C#3 bits (cont)

Shmuel Fomberg semuelf at 012.net.il
Fri Nov 28 04:59:36 PST 2008


Hi All.

In continue to the previous email, I saw the following piece of code:
var ids = new List<int>{1,2,3,4,5};
var sum = 0;
ids.ForEach(i => sum += i);

That's clearly a closure. but I understood that C# doesn't have closures?
Or maybe "sum" in only valid while in-scope. (one-way closure?) So you 
shouldn't do something like:
Func<int, int> GetSummer(...) {
    var sum = 0;
    return i => sum + i;
}

can you?

Shmuel.



More information about the Perl mailing list