pls copy paste program below and try it out... '************ Imports System
Module Program Sub inputproc(ByRef pstudarr() As String) Dim count As Integer For count = 0 To 3 Console.WriteLine("Input name " & count) pstudarr(count) = Console.ReadLine Next End Sub
Sub display(ByRef pstudarr() As String)
Dim count As Integer
For count = 0 To 3
Console.WriteLine(pstudarr(count))
pstudarr(count) = "zzzzzzz"
Next
End Sub
Sub Main(args As String())
Dim studarr(3) As String
Call inputproc(studarr)
Call display(studarr)
Console.ReadLine()
Call display(studarr)
End Sub
End Module '*************
next replace Sub display(ByRef pstudarr() As String)
with Sub display(Byval pstudarr() As String)
You will see... it is same output
SO IT SEEMS NO DIFFERENCE WITH BYVAL AND BYREF IN ARRAYS???
same output... seems byval and byref has no difference for arrays.
Anyone having same issues???
That's because an array is a reference type.
Passing a reference type to a method using
ByValmeans that the reference is passed by value - so if you change the reference to point to another instance of array, the changes will not reflect outside of your method.If you are passing the reference
ByRef, and assign it to another instance inside the method, that would reflect outside as well.For more details, read Jon Skeet's Parameter passing in C# (Don't worry, this also applies to Vb.Net).