LINQ
LINQ: Lambda Expressions, What is LINQ?, Common LINQ Methods, Query Syntax vs Method Syntax, Closures: Lambdas That Remember.
Updated
- Lambda Expressions (Apprentice): A lambda expression is a small method with no name, written where it's used, such as name => name.Length > 4. Pass one to a method like FindAll, RemoveAll or Sort, and that method runs it on each item.
- What is LINQ? (Journeyman): LINQ is ETL for the data in your program. Start from any collection, chain methods such as Where, OrderBy and Select that each transform the items, and finish with ToList, Count or First. A query runs when its results are used.
- Common LINQ Methods (Journeyman): The LINQ methods you'll use every day. Where, OrderBy, ThenBy and Select filter, sort and reshape; Count, Sum, Average, Min, Max, Any, All and GroupBy summarize; First, FirstOrDefault, Take, Skip and Distinct pick items.
- Query Syntax vs Method Syntax (Journeyman): LINQ can also be written in query syntax, from ... where ... orderby ... select, which reads like SQL. The compiler turns it into the same method calls. Method syntax is more common, and some methods, such as Count and First, have no query keyword.
- Closures: Lambdas That Remember (Journeyman): A lambda can use the local variables around it. It captures the variable itself, not a copy of its value, and keeps it alive for as long as the lambda lives, which is how a method can hand back a counter that remembers its count.