Delegates and Lambdas
Delegates describe callable signatures; lambdas provide concise inline implementations.
How it works
Pass strongly typed behavior as data.
Func<int,int,int> represents a method receiving two integers and returning one integer.
Runnable C# example
Program.cs
using System;
class Program
{
static int Apply(int left, int right, Func<int, int, int> operation)
=> operation(left, right);
static void Main()
{
int result = Apply(6, 7, (left, right) => left * right);
Console.WriteLine(result);
}
}
42Practice with the debugger
Set a breakpoint on an important assignment or condition, click Debug, and inspect the local values before stepping to the next line.