views:

64

answers:

2

I have this 2D array:

Private _Chars As String(,) = {{"`", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "="},
                                    {"¬", "!", """", "£", "$", "%", "^", "&", "*", "(", ")", "_", "+"}}

I want to Pass a Dimension (ie. the First Line) into a Function, or the Second Line into a function to switch between these two lists so that the function only requires a String() parameter not a String(,) parameter so I could loop through both like so:

Sub Example(Row as String())
  For Index as Integer = 0 To Row.Count - 1
    MessageBox.Show(Row(Index))
  Next
End Sub

And this function would loop though 12345 etc and !"£$% etc. If there is way to have the arrays work this was and that works in Silverlight - I would ge very grateful!

A: 

You could use a jagged array instead.

RedDeckWins
Guess you don't get any props for answering first.
RedDeckWins
Thanks for this as with the other answer I was still looking up this topic and found this type of array - just few examples of how they worked, so thanks for this anyway as I may have missed it.
RoguePlanetoid
+2  A: 

You can't do it (easily). Your best option is to create a jagged array (an array of arrays) like this:

Private _Chars String()() = { New String() {"`", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "="},
New String() {"¬", "!", """", "£", "$", "%", "^", "&", "*", "(", ")", "_", "+"}}

You could then call your function like this:

Example(_Chars(0))
Example(_Chars(1))
Rory
P.S. Sorry if my syntax is off, It's been years since I used VB.NET
Rory
Yes this was the kind of array I found - I'd never used one before, as this usage had never came up before. However I was not quite sure how to use them - so thanks for the example!
RoguePlanetoid