Lambda expressions — RexDac Academy

RexDac AcademyTechnical notes · Some prior knowledge helps
0%Published notes read · this device

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:

  1. The short "expression" way
Func<int, int> f = x => x + 1;
  1. The longer, "block body" way.
Action<string> log = s => { Console.WriteLine(s); };