我刚刚安装了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.