After reading the using
statement C# spec and looking around some of the implemented streams (memory, file, etc..) i see that the default behavior is to dispose the underlying streams when calling Dispose()
.
There are certain streams where you can explicitly state that you dont want to dispose of the underlying stream, like in DeflateStream
:
public DeflateStream(Stream stream, CompressionLevel compressionLevel, bool leaveOpen)
leaveOpen Type: System.Boolean true to leave the stream object open after disposing the DeflateStream object; otherwise, false.
Of course, you might work around the disposal by not using the using statement, or perhaps implementing a WrapperStream
class which wrap your stream and doesn't dispose the underlying stream.