gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 08:52:10 27 4
gpt4 key购买 nike

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

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com