为什么不再需要指明ByVal/ByRef?
我刚刚安装了 Visual Studio 2010 Service pack(在 Windows 更新上建议),我可以在“intellisense”上看到一个新功能,这意味着当我编写 Function
或 Sub
时在 VB.NET 中,它不会使用 ByRef
或 ByVal
自动完成参数...
1) 无论如何,我可以将此选项配置回之前的状态?
2)如果我不指定ByX
,默认使用哪一个? (看起来总是ByRef
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看来这篇文章涵盖了您的问题:
http://msmvps.com/blogs/carlosq/archive/2011/03/15/vs-2010-sp1-changing-quot-byval-quot-vb-net-code-editor-experience。 aspx
所以不,没有办法获得旧的行为。从现在开始,
ByVal
是默认值(之前的样子),并且不会自动添加到方法参数中。在我看来,这是一个很好的决定,因为它使 VB.NET 与 C# 更加一致,并避免了不必要的“噪音”(它已经足够冗长了)。
旧行为:
新行为
It seems that this post covers your question:
http://msmvps.com/blogs/carlosq/archive/2011/03/15/vs-2010-sp1-changing-quot-byval-quot-vb-net-code-editor-experience.aspx
So no, there is no way to get the old behaviour. From now on
ByVal
is the default (what it was before) and it won't get added automatically to the method parameters.In my opinion this is a good decision since it's making VB.NET a bit more consistent with C# and avoids unnecessary "noises"(it's already verbose enough).
Old behaviour:
New behaviour
蒂姆涵盖了您直接询问的内容,但要记住的其他事情是任何引用类型变量(例如用户定义的类)即使按值传递也将允许您对保留的实例属性等进行更改。但是它不允许您更改整个对象。这可能就是为什么您似乎默认引用
来自 MSDN:
Tim covered what you asked directly, but something else to keep in mind is that any reference type variable, like a user defined class even if passed by value will allow you to make changes to that instances properties etc that stay. It won't however allow you to change the entire object. Which may be why it seemed to you to be defaulting to by reference
From MSDN:
将例程传输到 VBA 时要小心,默认值为
ByRef
(请参阅 本页底部,作者:伟大的 Chip Pearson)。这可能会很混乱。
Beware when transferring routines to VBA, where the default is
ByRef
(see, e.g., "The Default Method Of Passing Parameters" at the bottom of this page, by the great Chip Pearson).That can be messy.