Click here to Skip to main content
13,348,874 members (76,845 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


8 bookmarked
Posted 2 Feb 2011

Multi-Line Lambdas in C# and VB.NET

, 3 Feb 2011
Rate this:
Please Sign up or sign in to vote.
Lambdas can be composed of multiple lines of code.
Thanks to a recent answer on CodeProject, I discovered that lambdas can be made using multiple lines of code (I always assumed they could only use a single line of code). Here is how it's done in C#:
Action<int, int> dialog = (int1, int2) =>
dialog(1, 2);

The key there is to use curly braces to create a code block to contain multiple lines. After some Google searching, I found that this can be done in VB.NET as well:
Dim dialog As Action(Of Integer, Integer) =
    Sub(int1, int2)
    End Sub
dialog(1, 2)

The key there is to add "End Sub" (or "End Function") and place each statement on a new line.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer
United States United States

  • Managing Your JavaScript Library in ASP.NET (if you work with and you don't read that, you are dead to me).
  • Graduated summa cum laude with a BS in Computer Science.
  • Wrote some articles and some tips.
  • DDR ("New high score? What does that mean? Did I break it?"), ping pong, and volleyball enthusiast.
  • Software I have donated to (you should too):

You may also be interested in...

Comments and Discussions

GeneralReason for my vote of 5 very good to put code for C# AND VB Pin
dg784-Feb-11 22:44
memberdg784-Feb-11 22:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180111.1 | Last Updated 3 Feb 2011
Article Copyright 2011 by AspDotNetDev
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid