What is the difference between lambdas and delegates in the .NET Framework?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Delegates and lambdas are related in C#, but they are not the same thing. A delegate is a type that represents a callable method signature, while a lambda is a compact syntax for writing an anonymous function that can often be assigned to a delegate.
Delegates Are Types
A delegate defines the shape of a callable target.
MathOperation is a real .NET type. It says:
- two
intinputs - one
intoutput
Any method matching that signature can be referenced by that delegate type.
Built-in delegate types such as Action and Func are just common reusable versions of the same idea.
Lambdas Are Syntax For Anonymous Functions
A lambda is a concise way to write a function inline:
Here the lambda (a, b) => a + b is not a delegate type. It is an anonymous function expression. The compiler can convert it to a compatible delegate type such as Func<int, int, int>.
That is the key distinction:
- delegate is the target type
- lambda is the code expression
Lambdas Usually End Up As Delegates
In everyday C# code, lambdas are often assigned to delegates:
This makes it easy to blur the concepts, because the lambda is immediately converted into a delegate instance.
But the conversion is still a conversion. The lambda and the delegate are not interchangeable ideas.
Lambdas Can Also Become Expression Trees
One reason the distinction matters is that lambdas do not always compile to delegates. They can also compile to expression trees.
This does not store an executable delegate directly. It stores a data structure describing the code. Frameworks such as LINQ providers use this to inspect query logic.
A delegate cannot do that by itself. It represents executable method references, not a parseable code tree.
So lambdas are more flexible at the syntax level than delegates are at the type level.
Why Delegates Still Matter
Delegates are the foundation behind:
- event handlers
- callbacks
- LINQ predicates
- '
FuncandAction'
For example:
The event is delegate-based. The lambda is just a convenient way to supply the handler.
Anonymous Methods Are Related Too
Before lambdas, C# had anonymous methods:
This is another way to create a delegate-compatible anonymous function. Lambdas are the more modern and concise syntax, but they serve a similar role.
That is another hint that lambdas are about expression syntax, not about replacing the delegate concept entirely.
A Good Mental Model
Keep this separation in mind:
- delegate answers "what callable shape is expected"
- lambda answers "what inline behavior do I want to provide"
Once you see it that way, confusing examples become easier to reason about.
For example, if a method asks for Func<string, bool>, that is a delegate type requirement. Supplying s => s.Length > 3 is one way to satisfy it.
Common Pitfalls
The biggest mistake is saying lambdas and delegates are the same thing. They are connected, but one is a type concept and the other is a syntax concept.
Another mistake is forgetting that lambdas can also become expression trees. In LINQ-to-Objects code that distinction is easy to ignore, but ORMs and query providers depend on it heavily.
People also assume custom delegates are obsolete because Func and Action exist. They are less common now, but still useful when you want clearer names or special semantics such as ref parameters.
Finally, when reading older C# code, remember that anonymous methods and lambdas solve similar problems with different syntax.
Summary
- A delegate is a .NET type representing a callable signature.
- A lambda is shorthand syntax for an anonymous function.
- Lambdas are often converted to delegates, but they can also become expression trees.
- Delegates power callbacks, events, and many standard library APIs.
- The clearest mental model is type versus syntax: delegate defines the shape, lambda provides the behavior.

