Lambda Expressions

Added in .NET Framework 3.5
You use a lambda expression to create an anonymous function.
Use the lambda declaration operator => to separate the lambda's parameter list from its body.

A lambda expression is an anonymous function that you can use to create delegates.
This lets you write local functions that can be passed as arguments or returned from functions.
A lambda expression is a block of code (an expression or a statement block) that is treated as an object. It can be passed as an argument to methods, and it can also be returned by method calls.
To create a lambda expression you specify the input parameters on the left of the lambda operator with an expression or statement block on the right
Multi-line lambda expressions were added to VB.Net in Visual Studio 2010.

string Person = peoplelist.Find(name => name.Contains("m") 

instead of

public string FindPerson(string contains, List<string> peoplelist) 
   for each (string name in peoplelist)
      if (name.Contains("m"))
         return name;
   return null;

© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited TopPrevNext