Delegates and Lambdas
Pass strongly typed behavior as data.
Introduction
Delegates describe callable signatures; lambdas provide concise inline implementations.
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.
Practice with a challenge
Use what this lesson covers to solve a real problem. Each challenge runs in your browser with instant tests and an AI review.
All challenges