?
Solved

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

Posted on 2012-08-24
2
Medium Priority
?
893 Views
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.
0
Comment
Question by:Cluskitt
2 Comments
 
LVL 25

Accepted Solution

by:
Luis Pérez earned 2000 total points
ID: 38328604
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.
0
 
LVL 18

Author Closing Comment

by:Cluskitt
ID: 38328606
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.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Introduction to Processes
Starting up a Project

840 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