title: How to dispose StreamReader and StreamWriter on the same memory stream?
body: <pre><code> class StreamReaderWriterDemo : AbastractDemo
  {
      public override void Run()
      {
          string message = "hello this is a test 0000";
  
          string result = string.Empty;
  
          try
          {
              using (var memoryStream = new MemoryStream())
              {
                  StreamWriter streamWriter = new StreamWriter(memoryStream, Encoding.Default);
                  this.WriteToStream(streamWriter, memoryStream, message);
                  memoryStream.Position = 0;
  
                  StreamReader streamReader = new StreamReader(memoryStream, Encoding.Default);
  
                  result = this.ReadFromStream(streamReader, memoryStream);
  
  
                  streamWriter.Dispose();
                  streamReader.Dispose();
              }
          }
          catch (Exception ex)
          {
  
          }
  
          Console.WriteLine(result);          
      }
  
  
      private void WriteToStream(StreamWriter streamWriter, MemoryStream stream, string message)
      {
              streamWriter.Write(message);
              streamWriter.Flush();
              streamWriter.Close();
      }
  
      private string ReadFromStream(StreamReader streamReader, MemoryStream stream)
      {
          string result;
  
              result = streamReader.ReadToEnd();
  
          return result;
      }
  }
  </code></pre>
  
  <blockquote>
    <p>I have trouble to dispose the streamReader reader, because the streamWriter.Dsipose() already disposed the memoryStream.</p>
  </blockquote>
  
  <p>So I am kind of confused, does it imply I don't have to dispose the StreamReader or streamWriter?</p>
  
  <p>What is correct way to dispose the StreamWriter, StreamReader that use the same memory stream?</p>
  
  <p>Please give me some advices?</p>