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,
staticvoid 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.
Join MindStick Community
You need to log in or register to vote on answers or questions.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
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,
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.