Why a BinaryWriter closes the outer Stream on disposal, and how to prevent that? (.NET C#)

后端 未结 4 1801
天命终不由人
天命终不由人 2020-12-06 09:06

I have one method that receives a Stream to write on it using a BinaryWriter. But when I dispose this BinaryWriter it also closes the stream. Can I leave it undisposed so I

4条回答
  •  一个人的身影
    2020-12-06 09:54

    As of .NET 4.5, the BinaryWriter class has a new constructor that takes a boolean parameter to indicate whether to leave the stream open or not.

    Ref: http://msdn.microsoft.com/en-us/library/gg712841.aspx

    public BinaryWriter(
        Stream output,
        Encoding encoding,
        bool leaveOpen
    )
    

提交回复
热议问题