Home > DeveloperSection > Forums > What is the syntax for Lambda Expressions in VB.NET?
Manoj Bhatt
Manoj Bhatt

Total Post:153

Points:1079
Posted on    January-14-2016 10:18 PM

 C# C#  .NET 
Ratings:


 1 Reply(s)
 248  View(s)
Rate this:
Sorry for dumb question, but I can not proper understanding of the lambda expression.please give me a appropriate answer?




Anupam Mishra

Total Post:135

Points:949
Posted on    January-15-2016 6:53 AM

In C#, Lambda expressions reduce the amount of work needed when iterating through data.  All enumerable data is queryable through LINQ with use of a SQL-like query (what I mean by that is the query looks like SQL, but is a different flavor). LINQ has an in-built mechanism to loop through enumerable data and use certain conditions setup in the where clauses to filter the data.  LINQ queries are quite effective in what they do.

Lambda expressions work in a similar way. Some of the existing extension methods feature built-in lambda expressions to perform certain actions and to make it easier to perform repetitive work.  We shall see this soon.  Lambda expressions do not require extension methods to work, but this is the most common usage currently.

For example, 

static void Main()

    {

     List<int> elements = new List<int>() { 100,200,300,400 };

      // ... Find index of first even element.

     int Index = elements.FindIndex(x => x % 2 = 0); //Here we using lambda expression

     Console.WriteLine(Index);

    }


As you can see, it is really easy to use lambda expressions and embeds them in your applications.  They really add a lot of functionality to an application. Lambda expressions are commonly exposed through static methods, but they can be used in other situations as well. Extension methods are not required, though this is the most common usage in the .NET Framework as of now.


Don't want to miss updates? Please click the below button!

Follow MindStick