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

标签 vb.net visual-studio-2010 byref byval

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

1)无论如何,我可以将此选项配置回以前的样子吗?

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

最佳答案

蒂姆直接介绍了您的要求,但是要记住的一点是,即使是按值传递,任何引用类型变量(例如用户定义的类)都可以使您对保留的实例属性等进行更改。但是,它不允许您更改整个对象。这可能就是为什么您似乎默认通过引用

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.

关于vb.net - 为什么不再需要指示ByVal/ByRef?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9207620/

相关文章:

c - 特殊的 Visual Studio 编译错误

c++ - sizeof 运算符的返回类型是什么?

c# - 重命名命名空间后无效的 .resx 文件

f# - address-of 和 ref 运算符之间的差异

vb.net - 如何转换整数?到VB.NET中的整数?

asp.net-mvc - 如何在 Razor 中传递带空格的字符串

f# - 为什么不能将带有 byref 的函数直接转换为委托(delegate)?

vb.net - 传递字符串时的 ByRef 与 ByVal 性能

vb.net - 如何在 VB.Net 中使用 Adob​​e Indesign API

mysql - 选中未选中的值时更新