title: Stream - Length of Content
body: <p>Is there no way to get the length of the content currently held by the stream?</p>
  
  <p>I thought Length would give me what I am looking for, but it did not match up in my test.</p>
  
  <pre><code>public class Solution {
  
      public static void Main(string[] args)
      {
          var raw = new byte[] { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5 };
          using (var stream = new MemoryStream(3)) {
              long size = stream.Length;              // Actual 0, expected 0
              long capacity = stream.Capacity;        // Actual 3, expected 3
              long position = stream.Position;        // Actual 0, expected 0
  
              stream.Write(raw, 0, raw.Length);
              size = stream.Length;                   // Actual 6, expected 6
              capacity = stream.Capacity;             // Actual 256, expected big enough to hold content
              position = stream.Position;             // Actual 6, expected 6
  
              var buffer = new byte[1];
              stream.Read(buffer, 0, 1);
              size = stream.Length;                   // Actual 6, expected 5
              capacity = stream.Capacity;             // Actual 256, expected same as before
              position = stream.Position;             // Actual 6, expected 5
  
              stream.Write(raw, 0, raw.Length);
              size = stream.Length;                   // Actual 12, expected 11
              capacity = stream.Capacity;             // Actual 256, expected same as before
              position = stream.Position;             // Actual 12, expected 11
  
              stream.Seek(0, 0);
              size = stream.Length;                   // Actual 12, expected 11
              position = stream.Position;             // Actual 0, expected 0
          }
      }
  }
  </code></pre>
  
  <p>I'd expect the read to decrease the size by 1. It apparently, does not. This raises the question then, if the byte is retained in memory and the length is reported including read bytes, when then is it removed from memory? (We can't accumulate forever!) and how do we get the Length of the current content? (total bytes written - total bytes read)?</p>
  
  <p>Edit:
  I've figured out that position remains at the end of the stream upon the first write, if you do not seek backwards. Position is shared for read and writes. However, the other questions still remain.</p>