I was reading about StreamWriter today, and came across this property, BaseStream.
I was looking for a definition and found this
“Gets the underlying stream that interfaces with a backing store.”
from here MSDN – StreamWriter.BaseStream
I understand what a BaseStream is for StreamReader, because it’s definition is very simply:
Returns the underlying stream.
But what does the definition of the StreamWriter.BaseStream mean?? Or more clearly, what does this part of the definition mean “interfaces with a backing store”? That sounds like gibberish to me.
You’re right; it does seem unnecessarily wordy, especially in comparison with the analogous
StreamReader.BaseStream. In reality, it just returns a reference to the underlying stream, exactly like StreamReader.I think the presumption of the description is that writing to the underlying stream will involve saving the written data to some sort of persistent store, such as a file. Of course, this isn’t necessary at all in reality (in the worst case, it could simply do nothing).
If you really wanted to extrapolate, you could interpret that as meaning that the underlying stream’s
CanWriteproperty istrue(at least at the point it was attached to the StreamWriter).To be convinced that it really is just returning the underlying stream, here’s the decompiled code from Reflector:
where the
streamfield is assigned in theInitmethod:which in turn is called by the constructor with the argument being the attached stream: