0

In documentation for StreamWriter (https://msdn.microsoft.com/en-us/library/wtbhzte9(v=vs.110).aspx) it says "The StreamWriter object calls Dispose() on the provided Stream object when StreamWriter.Dispose is called."

Is same true for BinaryWriter(Stream stream), I don't see same note in here (https://msdn.microsoft.com/en-us/library/atxb4f07(v=vs.110).aspx)?

I couldn't find anything either way in documentation, and the classes seem very related - one is for text files, the other for binary files, I expected same behavior in both and same note in both or neither.

Alex
  • 1,192
  • 14
  • 30
  • In general, readers or writers wrapping a stream will close the stream when the reader/writer itself is closed. But there usually will be an overload that will allow you to control that. – Jeff Mercado Mar 02 '17 at 22:44

1 Answers1

0

It does. If you don't want this behavior, there is an overload available that does not dispose the stream:

BinaryWriter(Stream output, Encoding encoding, bool leaveOpen)
Cory Nelson
  • 29,236
  • 5
  • 72
  • 110