VB返回值

dan983

我目前正在将一些代码从VB6.0迁移到VB.NET,并注意到了一个问题。我是VB6.0的新手,现在知道可以通过以下方式返回多个值:

Function test(str1 As String, str2 As String) As Long

str1 = "Hello World1"
str2 = "Hello World2"

test = 0

End Function

调试时,我可以看到传递的参数现在已更新。但是我的问题是VB.NET似乎没有做到这一点。如何在VB.NET中执行此操作?

任何意见,将不胜感激。

斯坦

在VB6中,默认情况下按引用传递参数,而在VB.NET中,默认情况下按值传递参数。这就解释了为什么它的行为有所不同。如果要保留旧的行为并通过引用传递参数,则需要对其进行明确说明(请注意其他ByRef关键字):

Function test(ByRef str1 As String, ByRef str2 As String) As Long

str1 = "Hello World1"
str2 = "Hello World2"

test = 0 'don't forget to migrate this line to VB.NET as well

End Function

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章