• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 916
  • Last Modified:

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

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
Cluskitt
Asked:
Cluskitt
1 Solution
 
Luis PérezSoftware Architect in .NetCommented:
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
 
CluskittAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now