When is GetBuffer() on MemoryStream ever useful?
问题 I've known that GetBuffer() on a MemoryStream in C#/.NET has to be used with care, because, as the docs describe here, there can be unused bytes at the end, so you have to be sure to look only at the first MemoryStream.Length bytes in the buffer. But then I ran into a case yesterday where bytes at the beginning of the buffer were junk! Indeed, if you use a tool like reflector and look at ToArray() , you can see this: public virtual byte[] ToArray() { byte[] dst = new byte[this._length - this.