Why is it not allowed to declare a void body for methods?

I had a method that has an empty body like this:

public void Foo()
{
}

As suggested ReSharper, I wanted to transform it into an expression body in order to save some space, and it became as follows:

public void Foo() => ;

What does not compile. Is there a specific reason why this is not supported?

And I think I should open the ticket with an error for ReSharper, because it will reorganize the code into a non-compiled version.

+6
source share
1 answer

, - ( "= > " ). void , Expression.Empty(), , Foo() (void) .

, void Task, , . (https://msdn.microsoft.com/en-us/magazine/dn802602.aspx)

.

public void Foo() => Expression.Empty();

, Resharper.

+8

Source: https://habr.com/ru/post/1016428/


All Articles