Solved

pass array of strings

Posted on 2009-05-18
3
195 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.Net - KeyPress Event 4 36
Error handling in asp.net site 5 28
VB.NET 2008 Publish Error 2 27
.NET 2008 VB and C# 6 28
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

777 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