Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
300 views
in Technique[技术] by (71.8m points)

c# - Can any one explain why StreamWriter is an Unmanaged Resource.

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 !!!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...