Solved

pass array of strings

Posted on 2009-05-18
3
199 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 86

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

Linux Academy Android App Now Supports Chromecast

We have some fantastic news for our Android fans. We’re so excited to announce that the Linux Academy Android app is now available with Chromecast support. That’s right – simply download the latest update of the Linux Academy App and start casting your favorite course videos!

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

617 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