Feature request: Implicitly typed lambdas
See original GitHub issueCurrently, it is not possible to do this:
var x = () => 1;
Instead, you need to declare the type before:
Func<int> x = () => 1;
C# should just assume these kind of lambdas are either Action or Func and infer the type.
Usually these lambdas are used as helpers for the method implementation, so it really wouldn’t matter if a (string s) => true
is a Func<string, bool>
instead of a Predicate<string>
as long as the signature matches.
Issue Analytics
- State:
- Created 9 years ago
- Comments:40 (19 by maintainers)
Top Results From Across the Web
Lambda improvements - C# 10.0 draft feature specifications
This feature specification describes a number of syntax improves that making declaring lambda expressions more convenient in a variety of ...
Read more >Implicit conversion from lambda expression to user-defined ...
I want to define an implicit conversion from (specific) lambda expressions to a user-defined type. I tried the following:
Read more >Lambda function versions
Lambda creates a new version of your function each time that you publish the function. The new version is a copy of the...
Read more >Announcing AWS Lambda Function URLs: Built-in HTTPS ...
Today, I'm happy to announce the general availability of Lambda Function URLs, a new feature that lets you add HTTPS endpoints to any...
Read more >Integrating Lambda Expressions and Events
Using lambda expressions is a more compact way of wiring up events in both C# and Visual Basic. It also provides a way...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Not a perfect solution, but remember that you can create aliases for closed generic type names when they get long:
The later:
This is one that we talk about often. VB has implicit types for delegates (not Func and Action but compiler generated ones), and quite liberal implicit conversions between delegate types.
We could do the same in C#, and maybe we should. One concern would be that the relative cost of these conversions might be on the highside, and invisible to users because of the implicit conversions.