documentation says
You should implement IDisposable only if your type uses unmanaged resources directly.
Based on the main Java background, this sounds weird to me. Suppose I have a class containing an IDisposable element:
class Foo : IDisposable {
private StreamWriter sw;
...
}
... and suppose this class is used, for example, as a kind of filter that takes strings and modifies them, and then outputs them using StreamWriter sw. I want to use this class as a kind of Writer.
Why don't I want to implement Dispose(bool)that would trigger sr.Dispose()?This is what I would need to do if I encoded it in Java (the Java interface is Closablesimilar to .NET IDisposable, although somewhat different). However, the documentation says that I should not, because I do not directly use unmanaged resources.
If I do not redefine Dispose(bool)how the managed resource swbecomes deleted when I leave the block launched by the statement using?
source
share