C# Why can partial methods use ref, but not out?

2020-02-24 16:43发布

Pretty straight forward. MSDN states that you can use ref, but not out for partial methods. I'm just curious as to the why? It was my understanding that when code is compiled, the partials are merged, so what is up with the restriction? Is there more to partial than just making code files cleaner and organized (i.e. eyecandy)?

Reference: MSDN Article - "Partial methods can have ref but not out parameters."

7条回答
劫难
2楼-- · 2020-02-24 17:19

Because unlike ref parameters, out parameters MUST be initialized before the method returns. If the partial method is not implemented (which is a valid scenario,) how can it be initialized?

查看更多
登录 后发表回答