Unify expression-bodied and normal method syntax #4538
Replies: 4 comments 5 replies
-
IMO the suggested syntax seems quite confusing and in trying to remove the difference between block-bodied members and expression-bodied members only seems to create 3 or 4 other forms of syntax to accomplish the same thing. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Presumably this also means that void Foo() Bar();
void Foo() if (cond)
{
Bar();
} etc all become valid? I really don't like that. Particularly with local functions: void Foo()
if (cond)
{
Bar();
}
Baz(); Baz isn't part of the local function, but it sure looks like it is. |
Beta Was this translation helpful? Give feedback.
-
Rust use A similar feature is championed at #3086 - maybe that could be extended to method blocks for the same effect. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
It feels wrong to have two distinct syntaxes for the same things.
Proposal: If we changed the syntax of methods from
method_header ( block | "=>" expression ";")
tomethod_header statement
(wherestatement
of course includesblock
as a possibility) and if we declaredreturn
and=>
to be synonyms, then we could write the same method asand, as a side-effect, we could write a lambda as
As an exception we should forbid the
return
keyword in void methods, property setters and constructors; however, we would allow the following syntax in these casesThe term "expression-bodied member" would become obsolete in C#.
Beta Was this translation helpful? Give feedback.
All reactions