Does specifying the OutAttribute on ByRef internal methods currently do anything?

后端 未结 2 1458
情歌与酒
情歌与酒 2021-01-11 23:02

VB.NET doesn\'t have out parameters, but you can specify ByRef on COM and P/Invoke methods to get the same effect for external method

相关标签:
2条回答
  • 2021-01-11 23:36

    I subclassed MembershipProvider with a VB class, we'll call it A, and then subclassed A with a C# class we'll call B. The C# code, B, was not recognizing the fact that the abstract methods in the MembershipProvider had already been implemented in the VB subclass, A, until I applied the OutAttribute in the VB class for parameters that were specified as out in the MembershipProvider base class abstract methods. This has an impact beyond just COM or P/Invoke.

    0 讨论(0)
  • 2021-01-11 23:46

    I've confirmed a VB.NET <Out()> does cause a C# client to require out arguments, so it does seem to be effectively the same.

    Also a C# client passes in its arguments with current values into the method, but that's not surprising because, unlike the COM or P/Invoke cases, there's no marshalling to do. (And C# won't allow a property to be set by an out argument directly, so there doesn't seem to be a way to see if C# would optimise away a previous unneeded assignment.)

    So it seems the answer is it does help possible future C# clients use the code, and if the jitter ever adjusts the C# equivalent, it would do the same here. Though because languages like VB exist, it can't do much because they don't respect the Out attribute themselves.

    0 讨论(0)
提交回复
热议问题