title: How do I "fork" a Stream in .NET?
body: <p>As <a href="https://stackoverflow.com/questions/1084813/why-a-binarywriter-closes-the-outer-stream-on-disposal-and-how-to-prevent-that">discussed before</a>, when a BinaryReader or BinaryWriter gets closed, its underlying Stream get closed as well (aargh).  Consider this situation: a routine <code>R</code> is passed a MemoryStream, say <code>M</code>; I would like to write some stuff to <code>M</code> and then pass it to another routine for more processing (not necessarily writing). For convenience, I'd like to wrap <code>M</code> in a BinaryWriter to do my writing. After writing, I'm done with the BinaryWriter but not with <code>M</code>. </p>
  
  <pre><code>void R(MemoryStream M)
  {
      using (B = new BinaryWriter(M))
      {
          // write some stuff using B
      }
  
      S(M);  // now pass M to another routine for further processing
  }
  </code></pre>
  
  <p>But, I can't dispose of the BinaryStream without closing <code>M</code>. </p>
  
  <p>Q: Is there a way to do any of the following?</p>
  
  <ul>
  <li>extract the underlying byte[] from a MemoryStream,</li>
  <li>clone a Stream</li>
  <li>reopen a Stream after it's been closed</li>
  </ul>