LINQ Operators and Lambda Expression - Syntax & Examples
LINQ is a cool feature in C# 3.0. Most of the developers are struggling for the syntax and examples. Here I have collected various examples for each operator in LINQ and the equivalent Lambda Expressions. Where IEnumerable < Product > x = products.Where(p => p.UnitPrice >= 10); IEnumerable < Product > x = from p in products where p.UnitPrice >= 10 select p; Select IEnumerable < string > productNames = products.Select(p => p.Name); IEnumerable < string > productNames = from p in products select p.Name; var namesAndPrices = products. Where(p => p.UnitPrice >= 10). Select(p => new { p.Name, p.UnitPrice }). ToList(); IEnumerable < int > indices = products. ...