ByVal 关键字的参数是值传参,ByRef 关键字的参数是地址传参。
-
ByVal的参数,是指定参数类型的值,不会改变传参对象的原地址值;
ByRef的参数,是指定原地址入参,是直接使用原地址对象,如果在方法里修改该对象的话,原地址的对象值也会改变,使用时慎用。
例子:
Public Class Form4
Private number As Integer = 1
Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
test2(number)
MsgBox(number)
test(number)
MsgBox(number)
End Sub
Private Sub test(ByVal num As Integer)
num += 1
End Sub
Private Sub test2(ByRef num As Integer)
num += 1
End Sub
End Class
本文出自 “12214653” 博客,请务必保留此出处http://12224653.blog.51cto.com/12214653/1928828