Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old June 27th, 2007, 01:18 AM
Authorized User
Join Date: Jun 2006
Posts: 47
Thanks: 0
Thanked 2 Times in 2 Posts
Default return more then one array from class file

hi all.

i have created a class file.
In class file i created a function with some input.
In that function i have created three arrays with some values.
now i want to return these three arrays from that single function.

how can i do this...
pl help.

Komila Kalia
Software Developer
Reliance engineering Associates (P) Ltd.
Old June 27th, 2007, 05:08 AM
Registered User
Join Date: Jun 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts

U cannot return more than one value or array from a single function.

U can create a hashtable and store those values as key and pair and return the hashtable and u can seggregate the values based on key.

Old June 27th, 2007, 06:28 AM
Authorized User
Join Date: Jun 2006
Posts: 47
Thanks: 0
Thanked 2 Times in 2 Posts

thnks banoo..
but i got the other way also as to create public arrays.
and returning the values.

thnks again.

Old June 27th, 2007, 12:39 PM
Authorized User
Join Date: Apr 2005
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts

You could also use "out" parameters to get more than one.

Old June 27th, 2007, 07:10 PM
planoie's Avatar
Friend of Wrox
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts

In my opinion, use public fields (i.e. arrays in your case) on the class for method return data isn't as clean an implementation as creating a return data structure that the method returns itself.

Also, with OO languages, I see no reason for out parameters. While it is true that you can only return "one" value from a method, that value can be anything.

While you could return an array of arrays, this requires you to know the magic numbers of the outer array for the inner values. Not very friendly for the method consumers.

What about creating a small class to contains the data to return? The class can have a public property for each array you need to return. That way you get a single return value (an instance of your return data class) that has logically named members for the data. This provides greater flexibility because you can address the data by an explicit name instead of a magic array index while also making it considerably more consumer friendly.

I use this pattern to create "ReturnArg" classes. The return argument classes often have status codes as well as the actual return data.


Similar Threads
Thread Thread Starter Forum Replies Last Post
return collection by function in class jimusa Visual Basic 2005 Basics 1 July 30th, 2008 03:18 PM
How to return an array ? arulkumar ASP.NET 2.0 Professional 0 March 3rd, 2007 03:15 PM
Java to XSL // Return Array go4java XSLT 3 June 29th, 2006 06:05 PM
How to return array value from a function nebpro BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 September 29th, 2004 12:14 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.