B
Boni
Dear all,
I found out that I don' understand byVal/byRef in VB.
There is a simple example:
Why in the first test the result is 10,10 where in the second 0,20.
Thanks for your help.
Boni
Module Module1
Class A
Public B As Integer
End Class
Sub test(ByVal val_ As A, ByRef ref_ As A)
val_.B = 10
ref_.B = 10
End Sub
Sub test2(ByVal aVal As A, ByRef aRef As A)
Dim A1 As New A
Dim A2 As New A
A1.B = 20
A2.B = 20
aVal = A1
aRef = A2
End Sub
Sub Main()
Dim A1 As A
Dim A2 As A
A1 = New A
A2 = New A
test(A1, A2)
Console.WriteLine(A1.B)
Console.WriteLine(A2.B)
A1 = New A
A2 = New A
test2(A1, A2)
Console.WriteLine(A1.B)
Console.WriteLine(A2.B)
End Sub
End Module
I found out that I don' understand byVal/byRef in VB.
There is a simple example:
Why in the first test the result is 10,10 where in the second 0,20.
Thanks for your help.
Boni
Module Module1
Class A
Public B As Integer
End Class
Sub test(ByVal val_ As A, ByRef ref_ As A)
val_.B = 10
ref_.B = 10
End Sub
Sub test2(ByVal aVal As A, ByRef aRef As A)
Dim A1 As New A
Dim A2 As New A
A1.B = 20
A2.B = 20
aVal = A1
aRef = A2
End Sub
Sub Main()
Dim A1 As A
Dim A2 As A
A1 = New A
A2 = New A
test(A1, A2)
Console.WriteLine(A1.B)
Console.WriteLine(A2.B)
A1 = New A
A2 = New A
test2(A1, A2)
Console.WriteLine(A1.B)
Console.WriteLine(A2.B)
End Sub
End Module