[Solved] Can any one explain why StreamWriter is an Unmanaged Resource.


StreamWriter is not an unmanged resource, its a .NET class, and it is 100% managed.

Another totally different thing is that StreamWriter might internally use unmanaged resources or own an IDisposable object that in turn might use an unmanaged resource, or simply extends a class that implements IDisposable.

The latter two are the reasons why StreamWriter implements IDisposable, but beware, implementing IDisposable does not necessarily mean that the class uses directly or indirectly unmanaged resources.

In the particular case of StreamWriter, it is obvious that it might indirectly consume unmanged resources; the underlying stream (the IDisposable instance field Stream stream) could be a FileStream which obviously consumes unmanaged resources (a file in your HD for instance). But its also very possible that the underlying stream doesn’t use any unmanaged resources, but as Colin Mackay correctly points out in commentaries below, all streams must implement a consistent interface which the abstract class Stream provides.

4

solved Can any one explain why StreamWriter is an Unmanaged Resource.