R
Razzie
Hi,
I know that as a general rule, whenever your class contains members that
implicitly or explicitly implement IDisposable, your class should too.
However, does it count when my class uses a using claus?
class A
{
private void doSomething()
{
using(StreamReader sr = new StreamReader(..))
{ // code }
}
}
1. Would class A still need to implement IDisposable, or is the using clause
completely 'safe'?
2. If I use a thy-catch clause around the using clause, and an exception
occurs, will some resources (the StreamReader) not get cleaned up properly?
(And maybe that would be the answer to number 1, eg. Yes I should still
implement IDisposable?)
3. When using the using clause, would I still need to call sr.Close()? I
take it the Close() method eventually calls the Dispose() method too, so it
wouldn't be necessary...
Thank you!
Razzie
I know that as a general rule, whenever your class contains members that
implicitly or explicitly implement IDisposable, your class should too.
However, does it count when my class uses a using claus?
class A
{
private void doSomething()
{
using(StreamReader sr = new StreamReader(..))
{ // code }
}
}
1. Would class A still need to implement IDisposable, or is the using clause
completely 'safe'?
2. If I use a thy-catch clause around the using clause, and an exception
occurs, will some resources (the StreamReader) not get cleaned up properly?
(And maybe that would be the answer to number 1, eg. Yes I should still
implement IDisposable?)
3. When using the using clause, would I still need to call sr.Close()? I
take it the Close() method eventually calls the Dispose() method too, so it
wouldn't be necessary...
Thank you!
Razzie