在 VB.NET 中调用过程的优缺点是什么?
我想知道在VB.NET中使用Call关键字和不使用Call调用程序的优缺点?
Private Sub ProOne()
' Code Are Here
End Sub
Private Sub Calling()
ProOne() ' I would like to know pros and cons of this
Call ProOne() ' And I would like to know pros and cons of this
End Sub
预先感谢大家。
I would like to know the pros and cons of calling procedures with Call Keyword and without Call in VB.NET?
Private Sub ProOne()
' Code Are Here
End Sub
Private Sub Calling()
ProOne() ' I would like to know pros and cons of this
Call ProOne() ' And I would like to know pros and cons of this
End Sub
Thanks in advance all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
没有优点,也没有缺点。
Call 关键字是旧 VB 方言中的遗留关键字。
在VB.net中它没有任何意义,是语法糖。
There are no pros, and there are no cons.
The Call keyword is a legacy keyword from older VB dialects.
In VB.net it has no meaning, and is syntatic sugar.
来自此处:
因此,本质上,ProOne() 和 Call ProOne() 在语义上是等效的。
From here:
So, in essence, ProOne() and Call ProOne() are semantically equivalent.
我发现的一个有趣的用途(建议R#)是当您需要创建一个实例只是为了调用时单个方法,然后将其标记为垃圾回收。
但不确定我是否保留它。
例如
相当于
One interesting use I found (R# suggested), was when you need to create an instance just to call a single method and then mark it for garbage collection.
Not sure if I'm keeping it though.
For example
equivalent of
尽管它们在技术上是等效的,但我反对使用“Call”。从 VB6 迁移到 VB.Net 时,重要的是要认识到它们是完全不同的语言,必须以完全不同的方式编写。不幸的是,Microsoft 希望为 VB6 开发人员提供支持,他们通过添加模仿 VB6 功能的功能来提供此支持,但明显逊色于 .Net 等效项。
切断与任何 VB6 遗留物的所有联系将使开发人员尽快停止使用这些位,并带来更好的代码输出。
Although they are technically equivalent, I would argue against using "Call". When moving from VB6 to VB.Net, it's important to realizae that they are completely different languages that have to be written for in completely different ways. Unfortunately, Microsoft wanted to provide support for VB6 developers, and they provided this by adding functionality that mimics the VB6 functionality, but is siginificantly inferior to the .Net equivalent.
Cutting all ties with any of the VB6 holdovers will make developers stop using these bits as quickly as possible, and lead to better code output.
来自文档
所以,
From documentation
so,
即使在 2019 年,Call 语句仍然具有相关性:“当被调用表达式不以标识符开头时,通常会使用 Call 关键字。不建议将 Call 关键字用于其他用途。”
调用语句 (Visual Basic)
MSDN 代码示例:
The Call statement still has relevance, even in 2019: "You typically use the Call keyword when the called expression doesn’t start with an identifier. Use of the Call keyword for other uses isn’t recommended."
Call Statement (Visual Basic)
MSDN code sample: