How to return nested string array from a function

M

moondaddy

I need to return a nested string array from a function and am getting hung
up on syntax. Here's a simple example of a function that returns the array
and how I'm trying to call it.

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim arr()() As String = Me.TestArr1
End Sub

Private Function TestArr1() As String
Dim arr()() As String = { _
New String() {"a00"}, _
New String() {"a10", "a11"}, _
New String() {"a20", "a21",
"a22"}}
End Function

Any help would be great!

Thanks.
 
J

Jay B. Harlow [MVP - Outlook]

Moondaddy,
Remember that:
Dim arr()() As String

is the same as:
Dim arr As String()()

This second syntax is required for function & property return types, amoung
other things.

So your TestArr1 function becomes:
Private Function TestArr1() As String()()
Dim arr()() As String = { _
New String() {"a00"}, _
New String() {"a10", "a11"}, _
New String() {"a20", "a21",
"a22"}} Return arr
End Function

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top