Passing arrays as parameters in Vb.Net
I have a class that contains an array and i would like to access the individual array elements in a form. I understand that VB.net does not allow the array to be public and i think i need to pass it as a parameter?
What i would like is on the form, to have a button when clicked, it checks the elements against each other to see if they are different (they are integers).
Re: Passing arrays as parameters in Vb.Net
VB.NET allows array variables to be public members of a class.
implement a property which wraps around the array:
\\\
Private m_Names() As String
Public Property Names() As String()
Get
Return m_Names
End Get
Set(ByVal Value As String())
m_Names = Value
End Set
End Property
///
Re: Passing arrays as parameters in Vb.Net
Hi,
I didnt understand what exactly u want, but i made u this code, hope this will help you.
Code:
Dim ARRAY1 As Int16() = {2, 3, 5, 6, 7}
Dim ARRAY2 As Int16() = {4, 2, 1, 3, 5}
Dim I As Int16
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Array_compare(ARRAY1, ARRAY2) Then
MsgBox("Arrays r equal")
Else
MsgBox("Arrays not equal")
End If
End Sub
Private Function Array_compare(ByVal arr1 As Int16(), ByVal arr2 As Int16()) As Boolean
For I = 0 To arr1.GetUpperBound(0)
If arr1(I) <> arr2(I) Then
Return False
'return false when it just find one item not equal
End If
Next
'returns true only if all items are equal
Return True
End Function