C
Christian Ahrenkiel
Hi,
I've got a DataSet (ds) which was created by a DataAdapter (da) method:
ds.Fill(ds).
This DataSet is passed through various methods (by value). Each method
changes some fields in the DataSet (for converting data in another format).
As this DataSet is _not_ class-wide declarated, each method returns the
changed DataSet and so it is passed through all methods and back to its
initial call.
Example:
private InititalCall()
{
DataSet ds;
// Filling DataSet via DataAdapter...
this.Method1(ds);
/* Although the returned DataSet is _not_ used, the DataSet (ds)
* shows all changes I did in Method1 and Method2!
* Normally I would have suspected, I would need an instruction like
*
* ds = this.Method1(ds)
*
* to apply the changes to my initial DataSet.
* Didn't I passed it by value? Why does it behave like by ref?
* Where is my fault? Is there a special behaviour I do not know yet?
*/
}
private DataSet Method1(DataSet ds)
{
// Some changes...
ds = this.Method2(ds);
return ds;
}
private DataSet Method2(DataSet ds)
{
// Some changes...
return ds;
}
Maybe anyone else is wondering...
Christian
P.S. The code sequence is just an example. I tried to symplify it, but I
am sure, in my real code sequence the DataSet is not class wide
declarated and not passed by ref.
I've got a DataSet (ds) which was created by a DataAdapter (da) method:
ds.Fill(ds).
This DataSet is passed through various methods (by value). Each method
changes some fields in the DataSet (for converting data in another format).
As this DataSet is _not_ class-wide declarated, each method returns the
changed DataSet and so it is passed through all methods and back to its
initial call.
Example:
private InititalCall()
{
DataSet ds;
// Filling DataSet via DataAdapter...
this.Method1(ds);
/* Although the returned DataSet is _not_ used, the DataSet (ds)
* shows all changes I did in Method1 and Method2!
* Normally I would have suspected, I would need an instruction like
*
* ds = this.Method1(ds)
*
* to apply the changes to my initial DataSet.
* Didn't I passed it by value? Why does it behave like by ref?
* Where is my fault? Is there a special behaviour I do not know yet?
*/
}
private DataSet Method1(DataSet ds)
{
// Some changes...
ds = this.Method2(ds);
return ds;
}
private DataSet Method2(DataSet ds)
{
// Some changes...
return ds;
}
Maybe anyone else is wondering...
Christian
P.S. The code sequence is just an example. I tried to symplify it, but I
am sure, in my real code sequence the DataSet is not class wide
declarated and not passed by ref.