Delphi doesn’t have Lambda Expressions and I’m a Delphi programmer, what am I missing out on

delphilambda

I'm nearly clueless as to what a lambda expression is, but I have a hard time believing that I couldn't finagle something to the same effect in Delphi (albeit with 900% more code).

What is the big advantage of lambda expressions, what am I missing out on and is there anything with the post Delphi 2009 RTL improvements that comes close to emulating the powers of C# in this regard?

Best Answer

Let's say in Delphi you have anonymous inline methods like the delegate in this C# code:

var squared = Enumerable.Range(0, 100)
    .Select(
         delegate(int a)
         {
             return a * a;
         }
    );

Then the lambdas are simply a shorter way of writing that:

var squared = Enumerable.Range(0, 100)
    .Select(
         a => a * a
    );

The code snippets above are identical from the IL point of view.