title: StringStream in C#
body: <p>I want to be able to build a string from a class that I create that derives from <code>Stream</code>. Specifically, I want to be able to write code like this:</p>
  
  <pre><code>void Print(Stream stream) {
      // Some code that operates on a Stream.
  }
  
  void Main() {
      StringStream stream = new StringStream();
      Print(stream);
      string myString = stream.GetResult();
  }
  </code></pre>
  
  <p>Can I create a class called <code>StringStream</code> that makes this possible? Or is such a class already available?</p>
  
  <p><strong>Update:</strong> In my example, the method <code>Print</code> is provided in a third-party external DLL. As you can see, the argument that <code>Print</code> expects is a <code>Stream</code>. After printing to the <code>Stream</code>, I want to be able to retrieve its content as a string.</p>