Why partial methods support ref but not parameters

I read on partial methods , as they will become much more important in updating C # -6 / Visual Studio 2013 2 in combination with Universal Windows Projects . While reading the documentation, I read this strange restriction on signing partial methods:

Partial methods may have ref parameters, but are not output.

I do not understand the reason for this limitation. Since partial methods are basically a normal method with a signature and implementation in different files, what technical reason would be to not support parameters? Or any other reason for this limitation in this regard. Moreover, they support ref parameters, which are very similar .

+6
source share
2 answers

If the partial method is declared but not implemented, it is not called.

This means that any out parameter is not assigned, which is not allowed.

This is not a problem with ref parameters, since they must be assigned before they are passed to the method, so they are definitely assigned even if the method is not called.

+8
source

It makes sense if you look at the details that you need to consider when implementing partial methods:

Partial methods are optional.

the out variable is never assigned a value, and the ref variable is always assigned a value. Consider the case where the incomplete method is not implemented, we will have a variable that is not assigned. No problem will arise for the variable ref, since it has a specific meaning.

In this regard, out variables are not supported, because the out variable means that the value is returned.

0
source

All Articles