Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing and Returning Objects 2

Status
Not open for further replies.

LenardD

Programmer
Dec 1, 2002
35
CA
Take the following code:

protected DataSet RunProcedure(string storedProcName, IDataParameter[] parameters, DataSet dataSet, string tableName )
{
// fill code
.....

return dataSet;
}

When the "dataSet" object is returned, what exactly gets returned.....a copy of the dataSet object or the reference to the dataSet object that was passed via the method?

Thanks.
 
The dataset. Functions return values, not references.

Craig
 
Thanks Craig. That is what I thought.

I don't know why one would want to code a method this way when one has a reference to the object to begin with. If you are dealing with a large dataset object, it's not very efficient.

Just some code I found in a book and thought "maybe I was missing something".

--Lenard
 
Lenard,

No, it's not efficient but remember that the original will get garbage collected as it will have gone out of scope.

It may be that something does happen under the covers that does pass a reference but I doubt it. For example, I may be returning the dataset to a client from the server directly.

Craig
 
Ummm, pretty sure it returns a reference, as a DataSet is a reference type (i.e. a class), not a value type (a struct). It's declared as:

Code:
public class DataSet : MarshalByValueComponent, IListSource, ISupportInitialize, ISerializable

Chip H.
 
Hmmm, OK. I think I will email the original author and see if he can confirm. I will let you know what he says.

Thanks Chip.

--Lenard
 
Chip,

You are right, you get back the original dataset.

Thanks for replying to my post.

--Lenard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top