VB.Net: Passing a variable dimension array into a function

Posted on 2012-08-24
Last Modified: 2012-08-24
I know that you can pass an array into a function like this:
Private Shared Function MyFunc(MyArr As String()) As String()
And I can pass a two dimension array like this:
Private Shared Function MyFunc(MyArr As String(,)) As String(,)

But how can I pass a variable dimension array into a function? That is, how can I make it so the function will accept a 1,2,3,etc-dimensional array without having to construct overloads? I would like to have a dynamic call to the function and have a simple check inside it. Constructing overloads will force a limit on how many dimensions I can use.
Question by:Cluskitt
    LVL 25

    Accepted Solution

    You can try this:

    Private Shared Function MyFunc(MyArr As Array) ...

    Inside your function, you can use several Array class functions to determine the number of dimensions (.Rank function), the upper and lower indexes for each dimensions (.GetUpperBound and .GetLowerBound functions) and so on.

    Hope that helps.
    LVL 18

    Author Closing Comment

    Excellent. That's what I was looking for. I know about the rank and bound methods, I just wasn't finding a way to send the array. Thanks.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: HTML5 Mobile App Development with PhoneGap

    PhoneGap can help you leverage your already existing HTML5, JavaScript, and CSS skills in order to create and deploy cross-platform mobile apps.This program comprehensively covers HTML5 mobile app development from top to bottom.

    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    This is an explanation of a simple data model to help parse a JSON feed
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    737 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

    19 Experts available now in Live!

    Get 1:1 Help Now