Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why partial methods can only have void return type?

what is the reason /logic/obstacle behind the fact that partial methods can only have void return type?

thanks

like image 615
pencilCake Avatar asked Mar 07 '12 11:03

pencilCake


2 Answers

Partial methods are designed to be left out if you did not provide an implementation for them. The compiler actually removes calls to partial methods that are not implemented.

This also highlights why they cannot return anything: If you relied on a return value without implementing the partial method, then what? You'd have something uninitialised, despite the code clearly showing an assignment.

Similarly, methods that use the Conditional attribute can only return void for the same reason. The method call may or may not exist in the compiled IL.

like image 85
Joey Avatar answered Oct 14 '22 10:10

Joey


Implementation of partial methods are intended as optional.

If the implementation is not provided, a call is still valid, but will be silently removed by the compiler. A delegate can only be assigned a partial methods which is implemented.

This means that they should have no side effects - effectively no return values or "out" parameters, they can not be virtual, and are always private.

More here.

like image 45
Robert Schmidt Avatar answered Oct 14 '22 11:10

Robert Schmidt