--- what is the reason preventing BinaryWriter object garbage collectionafter the WriteSomething method is executed? ---- using System; using System.IO; namespace Test { class Test { static void Main(string[] args) { using (Stream output = (Stream)File.OpenWrite("test.txt")) { WriteSomething(output); WriteSomethingElse(output); } } static void WriteSomething(Stream outputStream) { BinaryWriter writer = new BinaryWriter(outputStream); writer.Write("Something"); } static void WriteSomethingElse(Stream outputStream) { BinaryWriter writer = new BinaryWriter(outputStream); writer.Write("SomethingElse"); } } } --- Filip Strugar< fili @ sezampro_dot_yu>写道:Filip Strugar <fili@sezampro_dot_yu> wrote:它会被处理吗?当BinaryWriter / Reader被处理掉时,它会关闭底层流,所以不能再写(读)了! Will it get disposed? When BinaryWriter/Reader gets disposed, it closes the underlying stream, so no further writing (reading) on it is possible! 如果您*告知*它是Disposed,它只会被处置,或者使用 显式调用或使用using语句(或其他方法调用 调用它。) - Jon Skeet - < sk *** @ pobox.com> ; http://www.pobox.com/~skeet 如果回复小组,请不要给我发邮件It would only be Disposed if you *told* it to be Disposed, either withan explicit call or with a using statement (or another method callwhich called it).--Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeetIf replying to the group, please do not mail me too 这篇关于BinaryWriter / Reader问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 06-27 16:01