O'Reilly logo

Microsoft® Visual Basic® 2010 Developer’s Handbook by Klaus Löffelmann and Sarika Calla Purohit

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Lambda Expressions

Lambda expressions combine the best of delegates with the best of methods. Lambdas originate in functional programming. They link functions with object variables. In the simplest case, the code looks like the following example.

Companion Content

Open the corresponding solution (.sln), which you can find in the \VB 2010 Developer Handbook\Chapter 15\Lambdas\SimpleLambdaDemo folder.

Sub Main()

    Dim expressionLambda = Function(square As Double) square * square
    Dim expressionSub = Sub(ValueToPrint As Double)
                            Console.WriteLine(ValueToPrint.ToString) '"The following code "prints" 144. First 12*12 is executed, 'then the result is returned. expressionSub(expressionLambda(12)) 'Wait for key, so we can see something. Console.ReadKey() End ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required