Returning multiple arrays from function
Messages   Related Types
This message was discovered on microsoft.public.dotnet.languages.vb.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

mark (VIP)
I have a class with a function which need to return to the caller three
two-dimensional arrays. Right now the function sends the arrays as an array
of arrays. The caller then decomposes the array of arrays back to its
constituent arrays.

The trouble is I plan to make this class a class library which may be
consummed by CLS-compliant code. I understand that the new VB.NET array of
arrays feature is not CLS-compliant.

The arrays can be very large and I would like to avoid giving them class
level scope.

Does anyone have a CLS-compliant technique for sending three arrays with
procedure level scope from a function to a caller.
--
mark
Reply to this message...
 
    
Cor Ligthert
Mark,

Why not use an arraylistArray as return type

Private function myfunction (byval wathever as whatever) as arraylist()

Cor

Reply to this message...
 
    
Tom
Shouldn't you be able to return them as 3 By Ref arguments
in the function call?

[Original message clipped]

Reply to this message...
 
    
Tom Shelton
In article <Click here to reveal e-mail address>, mark wrote:
[Original message clipped]

I would just pass the arrays byref...

Sub MySub (ByRef array1(,) As Whatever, ByRef array2 (,) As Whatever....

HTH
--
Tom Shelton [MVP]
Reply to this message...
 
    
mark (VIP)
Yes Tom that's a way I may have to go. But, I would like to avoid it because
the arrays would have class level scope, i.e. they would continue to exist
(using memory) after their useful lifetime.

"Tom Shelton" wrote:

[Original message clipped]

Reply to this message...
 
    
Tom Shelton
In article <Click here to reveal e-mail address>, mark wrote:
[Original message clipped]

Why?

sub stuff()
dim array1(100, 100) as whatever
dim array2(1, 1) as whatever
dim array3(2, 1) as whatever

myobject.mysub (array1, array2, array3)

' do stuff with the arrays
end sub

I fail to see how passing the arrays to be filled makes them live past
their usefull lifetime?
--
Tom Shelton [MVP]
Reply to this message...
 
    
mark (VIP)
OK, I see now.

The instance of my class will call its own method to populate arrays which
are themselves class properties !

"Tom Shelton" wrote:

[Original message clipped]

Reply to this message...
 
    
Herfried K. Wagner [MVP] (VIP)
* "=?Utf-8?B?bWFyaw==?=" <Click here to reveal e-mail address> scripsit:
[Original message clipped]

This is not a VB.NET issue, it applies to all .NET programming
languages. The CLS simply doesn't support jagged arrays because there
may be programming languages that cannot deal with them.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Reply to this message...
 
    
mark (VIP)
OK,

Same question though. Is there another way to send three 2-D arrays from a
function which is CLS compliant but does not require those arrays to be
declared at class level?

"Herfried K. Wagner [MVP]" wrote:

[Original message clipped]

Reply to this message...
 
    
Herfried K. Wagner [MVP] (VIP)
* "=?Utf-8?B?bWFyaw==?=" <Click here to reveal e-mail address> scripsit:
[Original message clipped]

It doesn't make a difference where the array is declared. Jagged arrays
per-se are not CLS compliant. You'll have to look for another
datastructure, a list of lists for example ('ArrayList' or a typed list).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Reply to this message...
 
    
mark (VIP)
This array list sounds like a good solution.

I assume I declare an instance of arraylist then use the add method to enter
my 2-D arrays in my function then return the arraylist. Can 2-D arrays be
added to an arraylist?

In the caller, what method do I use to access the arrays in the list?

Finally, does it matter what scope the arrays have in the sender's class?

"Herfried K. Wagner [MVP]" wrote:

[Original message clipped]

Reply to this message...
 
    
Herfried K. Wagner [MVP] (VIP)
* "=?Utf-8?B?bWFyaw==?=" <Click here to reveal e-mail address> scripsit:
[Original message clipped]

Yes.

> In the caller, what method do I use to access the arrays in the list?

\\\
Dim Result As ArrayList = Foo.DoSomething()
For Each Row As ArrayList In Result.Items
For Each Item As ... In Row
...
Next Item
Next Row
///

> Finally, does it matter what scope the arrays have in the sender's class?

No. You only need to return a reference to the arraylist.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Reply to this message...
 
    
Charles Law
Hi Mark

If these arrays have some common theme (if only that they are all returned
by the same function) you could encapsulate them in a class. The you can
return just one object, and control exactly what happens to them and what
their scope is.

HTH

Charles

"mark" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
 
System.Collections.ArrayList




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com