在ByRef内部方法上指定OutAttribute当前是否有作用? [英] Does specifying the OutAttribute on ByRef internal methods currently do anything?

查看:178
本文介绍了在ByRef内部方法上指定OutAttribute当前是否有作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

VB.NET没有 out 参数,但是您可以指定< Out()>在COM和P / Invoke方法上使用ByRef ,以使外部方法获得相同的效果。

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

在内部方法(即仅方法)上指定相同.NET代码调用)实际上有助于抖动(或VB.NET编译器)吗?还是当前仅用作程序员注释?

Does specifying the same on internal methods (i.e. methods only called by .NET code) actually help the Jitter (or VB.NET compiler)? Or is it currently only useful as a programmer note.

是否有可能在以后的抖动中使用它,或者在编译时会丢失此属性?

Is it possible it could be used in a future Jitter, or is this attribute lost when compiling?

推荐答案

我已经确认VB.NET < Out()> 可以导致C#客户端需要 out 自变量,因此它似乎实际上是相同的。

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.

也有C#客户将其带有当前值的参数传递给方法,但这并不奇怪,因为与COM或P / Invoke情况不同,无需进行任何编组。 (而且C#不允许直接通过 out 参数设置属性,因此似乎没有办法查看C#是否可以优化先前的

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.)

所以看来答案是,它确实可以帮助将来的C#客户端使用该代码,并且如果抖动曾经调整了C#等效项,它将完成同样在这里。尽管由于存在VB之类的语言,所以它不能做很多事情,因为它们不尊重 Out 属性本身。

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.

这篇关于在ByRef内部方法上指定OutAttribute当前是否有作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆