Default Parameters in Lambda Expressions


With the release of .NET 10, C# 13 introduces a variety of quality-of-life improvements for developers. One of the standout features is the ability to define default parameter values in lambda expressions. This enhancement brings more flexibility and consistency to how we write inline functions.
What Changed?
Before C# 13, lambda expressions required all parameters to be explicitly supplied. If you wanted default values, you'd have to wrap your lambda in a method or use null checks and ternary operators inside the lambda body.
With C# 13, you can now define default values directly in the lambda parameter list, just like you can with regular methods.
Example
Here’s how it looks in practice:
Func<string, string, string> greet = (name = "World", prefix = "Hello") => $"{prefix}, {name}!";
Console.WriteLine(greet()); // Hello, World!
Console.WriteLine(greet("Developer")); // Hello, Developer!
Console.WriteLine(greet("Developer", "Hi")); // Hi, Developer!
This makes lambda expressions significantly more concise and expressive, especially when used in callbacks, event handlers, or functional programming patterns.
Why It Matters
Adding default parameters to lambdas helps in several ways:
Cleaner Code: Removes the need for wrapper methods or inline null checks.
More Expressive: The intent is clearer when default behavior is defined right at the parameter level.
Useful in Functional Scenarios: When passing lambdas into LINQ, configuration setups, or task pipelines, it reduces boilerplate.
Limitations
While this is a powerful feature, there are some caveats to be aware of:
You must use explicitly-typed lambda expressions. Type inference alone won't work when using default values.
This feature does not apply to anonymous methods (
delegate { }
).It may not be supported by older tooling or analyzers that haven't yet been updated for C# 13.
Summary
The default parameter values in lambda expressions is a small but impactful improvement in C# 13. It aligns lambdas more closely with traditional methods and opens up new, cleaner ways to write inline logic.
As C# continues to evolve alongside .NET, these kinds of enhancements demonstrate a strong commitment to developer productivity and language consistency.
References
Subscribe to my newsletter
Read articles from Renato Ramos Nascimento directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Renato Ramos Nascimento
Renato Ramos Nascimento
With over 14 years in software development, I specialize in backend systems using .NET, Python, and Java. I bring full lifecycle expertise, including requirements analysis, client/server and data layer development, automated testing (unit, integration, end-to-end), and CI/CD implementations using Docker, GitLab Pipelines, GitHub Actions, Terraform, and AWS CodeStar.