Hi Gustaf,
Sorry i wasn't clear. Dispose is exposed by IDispoable interface (see
there's casting ((IDisposable) c).Dispose(); ) which must be implemented
when using "using" statement. If you have a look at the SqlConnection class
you'll see it implements IDisposable interface. In other words, it's not
possible to apply "using" statement in conjunction with a class that does not
implement this interface, i.e.
using (Random random = new Random())
{
}
would not compile because Random class does not implement IDisposable
interface.
Hope it's clear now.
Regards
--
Milosz
[quoted text, click to view] "Gustaf" wrote:
> Milosz Skalecki [MCAD] wrote:
>
> > so as you can see Dispose() method is being called, which uses Close()
> > internally. Logically both snippets do exactly the same thing, but if you
> > plan to handle the exception in the code i would go for the second one.
>
> Many thanks, Milosz. Somewhat off-topic now, how can Dispose() call Close() internally? Does Dispose() always call a Close() method if there is one?
>
> Gustaf