Lambda expression in c #

Is there a situation where using a lambda expression is especially useful or is mainly used to write less code?

+6
c #
source share
2 answers

The rationale for adding lambdas to the language was two things.

(1) They enable syntax conversion of queries. When you say

from customer in customers where customer.City == "London" select customer 

It is getting

 customers.Where(customer=>customer.City == "London") 

(2) They can be converted to expression trees and thus do LINQ-to-SQL, LINQ-to-Entities, etc. possible. That is, they can represent both the ability to fulfill their semantics and the ability to test their structure.

+19
source share

Lambda expressions are syntactic sugar for anonymous methods , and their use cases are basically the same.

Lambdas can also be converted to expression trees.

Since they are much shorter and easier to write (at least for simple cases), this in itself is useful.

+2
source share

All Articles