Link to home
Start Free TrialLog in
Avatar of jagguy
jagguyFlag for Australia

asked on

pass array of strings

how do i pass an array of string as  a class parameter?

I want to cycle through the passed array of string by index as well.
is this correct to receive a array of strings in vb.net?  
 
Dim _mystrings(10) As String
    Public Sub New(ByVal mystrings() As String)
    
 
        _mystrings(0) = mystrings(0)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of GuitarRich
GuitarRich
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Fernando Soto
Hi jagguy;

Because this is not the default constructor you need to also call InitializeComponent if this is a Form class.

    Dim _mystrings(10) As String

    Public Sub New(ByVal mystrings() As String)
        InitializeComponent()
        _mystrings(0) = mystrings(0)
    End Sub

Fernando
*** NOT FOR POINTS ***

Just FYI, the loop can also be written as:

        For n As Integer = 0 To mystrings.GetUpperBound(0)
            ' do something with mystrings(n) here
        Next