-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Proposal]: Explicit lambda return type #4934
Comments
The spec linked has the following example which caught my attention: var f5 = () : string => null; // System.Func<string> Shouldn't this be: var f5 = string () => null; // System.Func<string> ? The document mentions that the explicit return type should come before the arguments, so it feels to me this should still apply for a lambda without arguments ( Otherwise, where is the explanation for this |
Thanks @julealgon. That example was from an earlier iteration of the proposal. I've corrected the example in #4728. |
f = static void (_) => { }; // ok What's the meaning of And is this feature also include declare method group / natural function as function parameter? |
https://github.com/dotnet/csharplang/blob/main/proposals/csharp-9.0/static-anonymous-functions.md
This is already possible with Action/Func (and the generic variations). |
@CyrusNajmabadi I know, what I mean is not as |
What is a pure method group? |
@CyrusNajmabadi Was it called natural function? There was always something that was exist as an object without proper type in dotnet that was a method that was not converted to My point is it should become first class citizen already instead of require to be converted to |
No clue.
Yes. That's what lambdas are. Prior to C# 10 tehy were typeless, and had to be given a type in the code to convert to. Now in C# 10, absent a type in source to convert to, they will naturally convert to Action/Func.
It is. The first class citizen is Action/Func. :) |
// OK.
var f = int (string s) => s.Length;
// Error. IIRC, this is rejected intentionally.
dynamic d = int (string s) => s.Length;
// Error. Is this intentional?
var a = new { m = int (string s) => s.Length }; |
From lambda-improvements.md:
|
Summary
Allow lambdas with explicit return type:
int (int x, int y) => x + y
.Allow lambdas with attributes
Infer a natural delegate type for lambdas and method groups
https://github.com/dotnet/csharplang/blob/main/proposals/csharp-10.0/lambda-improvements.md
Design meetings
ref
return syntax)The text was updated successfully, but these errors were encountered: