I was reading up on partial methods since they will become a lot more important in C#-6 / Visual Studio 2013 update 2 in combination with Windows Universal Projects. While reading the documentation I read this weird limitation on the signature of partial methods:
Partial methods can have ref but not out parameters.
I don't understand the reason for this limitation. Since partial methods are basically a normal method with the signature and implementation in different files, what technical reason would there be to not support out parameters? Or any other reason for this limitation for that matter. Especially since they do support ref parameters which are very similar.
ref is used to state that the parameter passed may be modified by the method. in is used to state that the parameter passed cannot be modified by the method. out is used to state that the parameter passed must be modified by the method.
Similar to a partial class, a partial method can be used as a definition in one part while another part can be the implementation. If there is no implementation of the partial method then the method and its calls are removed at compile time. Compiler compiles all parts of a partial method to a single method.
Partial Class is a unique feature of C#. It can break the functionality of a single class into many files. When the application is compiled, these files are then reassembled into a single class file. The partial keyword is used to build a partial class.
A partial method has its signature defined in one part of a partial type, and its implementation defined in another part of the type. Partial methods enable class designers to provide method hooks, similar to event handlers, that developers may decide to implement or not.
If a partial method is declared but not implemented, it does not get called.
This would mean that any out
parameter does not get assigned, which is not allowed.
This isn't a problem with ref
parameters, as they have to be assigned before they are passed to the method, so they are definitely assigned even if the method is not called.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With