Lamda Expression: It is an unnamed method written in the place of delegate instance. The symbole => is called Lamda operator.
LINQ :- Linq(Language Integrated Query) integrates query syntax inside the c# programming language. It is collection of standard query operators which provides query facility in .NET framework language like c#, VB.NET.
There is no difference in performance because after compile they generate same IL code for the same query.
Code in Linq :-
var query = from e in EmployeeList
where e.Age > 24
select e;
Same code in Lamda Expression:-
var query1 = EmployeeList.Where(e => e.Age > 24);
LINQ Code Sample :-
1. var query = from c in CustomerList
join p in PurchaseList on c.ID equals p.CustomerId
select c.Name + " " + p.ItemName
2. var query2 = (from e in EmployeeList
where e.Name.StartsWith("a")
select e).ToList();
3. var query3 = from c in CustomerList
join p in PurchaseList on c.Id equals p.CustomerId into Cart
from c in Cart.DefaultIfEmpty()
select new {custName=c.Name, Price=cp==null?(decimal?) :cp.Price };
Lamda Expression Code Sample :-
1. var query= Enumerable
.Range(1, 100)
.Where(x => (x % 2) == 0)
.ToList();
2. var query2 = EmployeeList.Where(e=> e.Name.StartsWith("a")).ToList();
3. var query 3 = CustomerList
.GroupBy (o => o.CustomerID)
.Select (o => new { CustomerID = o.Key, TotalOrders = o.Count () })