-
Notifications
You must be signed in to change notification settings - Fork 4.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: Allow block-statements with return values everywhere an expression is expected #15821
Comments
also related to #15651 |
I think seeing static int MyMethod()
{
var x = 2;
{
return x + 4;
}
// unreachable.
} With this proposed syntax, you could do: static in MyMethod()
{
var x = 2;
var y = {
return x + 4;
};
// Suddenly this is reachable.
return y;
} In quickly visually scanning a method, it seems like the |
Closing this out. We're doing all language design now at dotnet/csharplang. If you're still interested in this idea let us know and we can migrate this over to a discussion in that repo. Thanks! |
I propose to allow the following syntax:
var x = {var foo = Foo(); return foo * 3;};
As another example, in ternary operators, this will look like:
var x = condition ? {var foo = Bar(); return foo + 1;} : 2;
Such a syntax increases the composability of the language, allowing one to express logic using a natural flow, while also limiting the scope of local intermediary variables.
F# has a similar syntax, allowing to define arbitrarily nested expressions.
The text was updated successfully, but these errors were encountered: