VB.Net、EventArgs、ByRef 和 ByVal

发布于 2024-12-21 16:38:20 字数 769 浏览 4 评论 0原文

在 VB.Net 中,我有一个名为 WorkflowButtonEventArgs 的对象,它继承自 System.EventArgs

WorkflowButtonEventArgs 类包含两个 ByRef 属性。这些是内存中的对象,我不希望它们以任何方式重复或复制。

我可以在 VB.Net 中传递 WorkflowButtonEventArgs 对象 ByVal 并让它仍然保留 WorkflowButtonEventArgs 中的两个 ByRef 定义吗?

具体来说,如果我传递 ByVal:

Dim e As New WorkflowButtonEventArgs(...) ' e has some ByRef properties

RaiseEvent SomeEventName(e) ' e is passed ByVal

eWorkflowButtonEventArgs 类)中的 ByRef Properties/Members 是否不会在内存中复制或重复?

长话短说:我可以传递 e ByVal,还是需要传递它 ByRef 因为它包含 ByRef属性?

In VB.Net, I have an object named WorkflowButtonEventArgs that inherits from System.EventArgs.

The WorkflowButtonEventArgs class contains two ByRef Properties. These are objects that are in memory, and I do not want them duplicated or copied in any way.

Can I pass the WorkflowButtonEventArgs object ByVal in VB.Net and have it still preserve the two ByRef definitions in WorkflowButtonEventArgs?

Specifically, if I pass it ByVal:

Dim e As New WorkflowButtonEventArgs(...) ' e has some ByRef properties

RaiseEvent SomeEventName(e) ' e is passed ByVal

Will the ByRef Properties/Members in e (WorkflowButtonEventArgs class) not be copied or duplicated in memory?

Long-story-short: Can I pass e ByVal, or do I need to pass it ByRef since it contains ByRef Properties?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

紧拥背影 2024-12-28 16:38:20

我可以传递 e“ByVal”,还是需要传递“ByRef”,因为它包含“ByRef”属性?

是的。即使您的 EventArgs 通过 ByVal 传递,引用指向的对象也不会被复制。

Can I pass e "ByVal", or do I need to pass it "ByRef" since it contains "ByRef" Properties?

Yes. The objects pointed to by the reference will not get copied, even if your EventArgs is passed ByVal.

最偏执的依靠 2024-12-28 16:38:20

引用对象不会在内存中重复。参数上的 ByRef 关键字仅意味着您可以更改调用代码中参数下的变量的值。

Reference objects wont be duplicated in memory. The ByRef keyword on a parameter only means that you can change the value of a variable underlying the argument in the calling code.

提笔书几行 2024-12-28 16:38:20

实现目标的另一种方法是创建一个存储这两个属性的单例。

Another way to achieve your goal would be to create a singleton that would store the two properties.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文