微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

vb.net – 为什么不需要再指示ByVal/ByRef?

我刚刚安装了Visual Studio 2010 Service Pack(在Windows Update上提出),我可以看到“Intellisense”上的一个功能,这意味着当我在VB.NET中编写一个Function或Sub时,它不会使用ByRef自动完成参数或ByVal …

1)有没有可以配置这个选项回到之前呢?

2)如果我不指定ByX,认使用哪一个? (似乎总是ByRef)

Tim涵盖了您直接询问的内容,但要注意的其他事项是,任何引用类型变量(如用户定义的类即使通过值传递)也将允许您对该实例属性等进行更改。然而,它不会允许您更改整个对象。这可能是为什么你似乎认通过引用
Public Sub (Something As WhateverClass) 
  Something = New WhateverClass 'will result in no changes when outside this method

  Something.Property1 = "Test"  'will result in an updated property when outside this method
End Sub

MSDN

The value of a reference type is a pointer to the data elsewhere in memory. This means that when you pass a reference type by value,the procedure code has a pointer to the underlying element’s data,even though it cannot access the underlying element itself. For example,if the element is an array variable,the procedure code does not have access to the variable itself,but it can access the array members.

原文地址:https://www.jb51.cc/vb/256154.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐