为什么不再需要指示 ByVal/ByRef? [英] Why is it not necessary to indicate ByVal/ByRef anymore?

查看:17
本文介绍了为什么不再需要指示 ByVal/ByRef?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚安装了 Visual Studio 2010 Service Pack(在 Windows 更新中建议),我可以在智能感知"上看到一个新功能,这意味着当我编写 FunctionSub 在 VB.NET 中,它不会使用 ByRefByVal...

I just installed Visual Studio 2010 Service pack (proposed on Windows Update), and I can see a new feature on the "intellisense" that means when I write a Function or Sub in VB.NET it doesn't auto-complete parameters with ByRef or ByVal...

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

1) Is there anyway that I can configure this option back to how it was before?

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

2) If I don't specify ByX, which one is used by default? (it seems like it is always ByRef)

推荐答案

Tim 涵盖了您直接询问的内容,但要记住的另一件事是任何引用类型变量,例如用户定义的类,即使按值传递也将允许您可以更改保留的实例属性等.但是,它不允许您更改整个对象.这可能就是为什么在您看来默认为引用

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

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.

这篇关于为什么不再需要指示 ByVal/ByRef?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆