"Robert May" <ra****************@hotmail.com> wrote in message
news:Or**************@TK2MSFTNGP11.phx.gbl...
Question,
Say I have the following:
Using(DataSet ds=new DataSet)
{
...
da.fill(ds)
...
return ds;
}
What happens? Does the using dispose the dataset?
Yes. Return is supposed to
stop execution immediately, correct?
Except for Finally blocks which are guaranteed to run. The using block is
just shorthand for
try
{
da.fill(ds)
...
return ds;
}
finally
{
ds.Dispose();
}
Here after the return statement the finally block is executed.
You shouldn't be Disposing your DataSets. They don't really need it.
DataSet inherits IDisposable from MarshalByValueComponent. This is all junk
required for dragging and dropping DataSets onto Forms in design view, and
just confuses the runtime behavior of the the DataSet. Disposing a DataSet
doesn't really do anyting, so in your code your function will return a
disposed, but perfectly useful DataSet.
David