C# ADVANCEDChapter 5 · C# Advanced
Delegates and Lambdas
A delegate is a type that represents references to methods. Modern C# uses pre-defined delegates like Action (no return) and Func (returns a value) paired with lambdas.
Worked example
using System;
class Program {
static void Main() {
Func<int, int> square = x => x * x;
Console.WriteLine(square(5));
}
}How it reads
- Func<int, int> is a delegate taking an int and returning an int
- **x => x * x** is a lambda expression performing the math operation

Cloud tip: Use Action for methods that return void (no value), and Func for methods that return a value.


