Level 6 — Generics and Delegates
Lambda expressions
Original notes by SunDiaL · View English source
Lambda expressions are the modern, concise way to create anonymous functions.
A lambda uses the => syntax. It can be used anywhere a delegate is expected. There's two ways of creating a function:
- The short "expression" way
Func<int, int> f = x => x + 1;
- The longer, "block body" way.
Action<string> log = s => { Console.WriteLine(s); };