Hi,
The msdn doc for MemoryStream has two conflicting statements
about accessing a MemoryStream's buffer after it's been closed:
The buffer is still available on a MemoryStream once
the stream has been closed.
But later it says:
Attempting to manipulate a stream after it has been
closed might throw an ObjectDisposedException.
So what's the correct idiom to do write and then extract
binary data from a MemoryStream:
MemoryStream ms = new MemoryStream();
BinaryWriter bw = new BinaryWriter(ms);
bw.Write(123);
bw.Write("hello, world");
bw.Close(); // should this be flush instead???
byte[] data = ms.ToArray();
ms.Close();
Also, does one typically need to Dispose() a MemoryStream to
free it's internal buffer? (Doesn't bw.Close() call ms.Close()
so it can't free the buffer?)
Thanks,
Keith