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

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

问题描述

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

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天全站免登陆