You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since this was briefly mentioned in #5154 I've decided to create a separate issue for this discussion.
1. Blocks inside method bodies are expressions and return the value of their last expression.
letx={let a =1;letb=2;a+b;}
2. You cannot end a block inside a method body with a declaration or a statement that isn't guaranteed to not return if its return value is used.
letx={let a =1;letb=2;a+b;inty;//I won't compile!}
3. if is now an expression and accepts expressions as its two branches and returns the value of the one that is executed. When the return value of if is used its else branch becomes mandatory.
letx=
if (list!=null&& list.Count >0){
list[list.Count -1];} else {
getSomeDefaultValue();}lety=
if (list!=null&& list.Count >0){
list[0];}//I won't compile!
4. for, foreach, while and do ... while are not expressions (because their body can be executed zero times).
5. try and its derivatives are now expressions and return the value of the try block when no exception is thrown and the value of a catch block when an exception is caught by one. The value of the finally block is discarded.
Since this was briefly mentioned in #5154 I've decided to create a separate issue for this discussion.
1. Blocks inside method bodies are expressions and return the value of their last expression.
2. You cannot end a block inside a method body with a declaration or a statement that isn't guaranteed to not return if its return value is used.
3.
if
is now an expression and accepts expressions as its two branches and returns the value of the one that is executed. When the return value ofif
is used itselse
branch becomes mandatory.4.
for
,foreach
,while
anddo ... while
are not expressions (because their body can be executed zero times).5.
try
and its derivatives are now expressions and return the value of thetry
block when no exception is thrown and the value of acatch
block when an exception is caught by one. The value of thefinally
block is discarded.6.
switch
is not an expression (because there'smatch
.)7. You cannot yield a value of a non-final expression in a block.
The text was updated successfully, but these errors were encountered: