ByVal与ByRef的区别。
Module Module1
'比较一下byval,byref的区别
Sub Main()
Dim x As Integer, y As Integer
x = 10
y = 20
Swap1(x, y) '不改变原有值
Console.WriteLine("X is " & CStr(x) & " and Y is " & CStr(y))
x = 10
y = 20
Swap2(x, y) '改变原有值
Console.WriteLine("X is " & CStr(x) & " and Y is " & CStr(y))
Console.ReadLine()
End Sub
Private Sub Swap1(ByVal X As Integer, ByVal Y As Integer)
Dim t As Integer
t = X
X = Y
Y = t
End Sub
Private Sub Swap2(ByRef X As Int16, ByRef Y As Integer)
Dim t As Integer
t = X
X = Y
Y = t
End Sub
End Module