Solved

pass array of strings

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

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now