C# 14: Modifiers on simple lambda parameters without explicit parameter types
Introduction
C# keeps evolving, and each version brings small improvements that make everyday code a bit nicer to work with. C# 14 introduces one of those quality-of-life enhancements: you can now apply parameter modifiers ref, in, out, scoped, ref readonly directly on simple lambda parameters without having to write the parameter types. Until now, if you used a modifier in a lambda, you had to spell out the type, even when the delegate already provided it. With C# 14, you keep the modifier, drop the type, and let the compiler infer it. It’s not a groundbreaking feature, but it definitely reduces noise in ref-heavy or performance-oriented code.
What changed?
Before C# 14, using a modifier like ref or out meant you had to include the full parameter declaration, even though the delegate already told the compiler that the parameter was a ref int, you still had to repeat it. With C# 14, you can simplify this. Example:
The modifier stays, the type disappears, and everything still compiles cleanly. This keeps lambdas shorter and more pleasant to read, especially when the type isn’t important to the reader.
Syntax
The new rule is straightforward:
If the delegate (or the target lambda context) already defines the parameter types, you are free to omit them in the lambda as long as you keep the modifier.
Examples:
(ref x) => ...
(in span) => ...
(out result) => ...
(ref readonly value) => ...
(scoped s) => ...
Limitations
A few things to keep in mind:
- You must still write the modifier, only the type becomes optional.
- The target delegate must use the same modifiers, otherwise the lambda won’t match.
paramsis not supported by this feature, types must be explicit when usingparams.- Expression trees still impose their own restrictions.
- In complex lambdas with many parameters, leaving types implicit might hurt readability.
This feature is about removing noise, not hiding information.
When should you use it?
This feature shines when:
- You work with
Span<T>,ReadOnlySpan<T>, or ref-like types - Your APIs rely on callbacks that use
ref,in, orout - You want cleaner lambdas without duplicated types
- You write performance-focused or low-allocation code
For everyday business logic, you may not use this often, but in library development or systems programming, it’s a very welcome improvement.
Summary
C# 14 lets you apply modifiers like ref, in, out, scoped, and ref readonly to lambda parameters without specifying their types, as long as the delegate already defines them. It’s a small but meaningful improvement that keeps lambdas concise and expressive while maintaining clarity around reference semantics.