Solved

pass array of strings

Posted on 2009-05-18
3
196 Views
Last Modified: 2013-12-17
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

0
Comment
Question by:jagguy
3 Comments
 
LVL 12

Accepted Solution

by:
GuitarRich earned 500 total points
ID: 24411682
that method signature should work. To cycle through them you can use a For...Next loop like this:

For n As Integer = 0 To _mystrings.count - 1
    ' do something with _mystrings(n) here
Next
 
'or
 
ForEach s As String In _mystrings
    ' do somthing with s here
Next

Open in new window

0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 24411816
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
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 24412801
*** 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
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question