Replies: 6 comments
-
Alternatively the following syntax might be possible with "expression-bodied everything": public int GetValue(int input) =>
try
{
DoSomething(input);
return 0;
}
catch(Exception e)
{
Console.WriteLine("GetValue input : " + input);
}
finally
{
return input;
}; and int val;
public int Value
{
get =>
try
{
DoSomething();
return val;
}
catch(Exception e)
{
};
set =>
try
{
DoSomething(value);
val = value;
}
catch(Exception e)
{
Console.WriteLine("Set value " + value);
};
} |
Beta Was this translation helpful? Give feedback.
-
variables in separate blocks have different scope and lifetime. I don't think there should be an exception to this rule.
On the other hand, method body should have one block. following code, body of method is fragmented across multiple blocks, imho it does not improve readability of code, it actually reduces readability.
|
Beta Was this translation helpful? Give feedback.
-
@MkazemAkhgary Sure public try int GetValue(int input) // input is parameter before the scope
{
int x;
}
catch
{
// x has no definition here.
return input; // but input has
} |
Beta Was this translation helpful? Give feedback.
-
I dislike this even more than #958. We need to stop mixing method body with method signature declaration. |
Beta Was this translation helpful? Give feedback.
-
#908 is a similar proposal. |
Beta Was this translation helpful? Give feedback.
-
@gulshan Yeah that's right but I see no one like implicit try so I think explicit would be better |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
A simple syntactic sugar
Would be transpiled to
Should also work in local function and property?
Beta Was this translation helpful? Give feedback.
All reactions