Want to understand what part of StreamWriter source code is Unmanaged code. Have went through the code in http://referencesource.microsoft.com/ website.
But it seems to be complex code to understand,there is good comments in the source code. But still had tough time to understand, may be my knowledge is not upto that mark. However , if anybody has any blog or article that can answer this question. it will be great !!!
StreamWriteris not an unmanged resource, its a .NET class, and it is 100% managed.Another totally different thing is that
StreamWritermight internally use unmanaged resources or own anIDisposableobject that in turn might use an unmanaged resource, or simply extends a class that implementsIDisposable.The latter two are the reasons why
StreamWriterimplementsIDisposable, but beware, implementingIDisposabledoes 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 (theIDisposableinstance fieldStream stream) could be aFileStreamwhich 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 classStreamprovides.