title: Need help understanding Stream.Read()
body: <p>I am a little confused as to the steps of reading a file into buffer gradually. </p>
  
  <p>from the MSDN docs</p>
  
  <pre><code>public abstract int Read(
      byte[] buffer,
      int offset,
      int count
  )
  </code></pre>
  
  <p>source from <a href="http://www.csharp-examples.net/filestream-read-file/" rel="nofollow">C# Examples</a></p>
  
  <pre><code>FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
  try
  {
      int length = (int)fileStream.Length;  // get file length
      buffer = new byte[length];            // create buffer
      int count;                            // actual number of bytes read
      int sum = 0;                          // total number of bytes read
  
      // read until Read method returns 0 (end of the stream has been reached)
      while ((count = fileStream.Read(buffer, sum, length - sum)) &gt; 0)
          sum += count;  // sum is a buffer offset for next reading
  </code></pre>
  
  <p>can I say that the line <strong><code>fileStream.Read(buffer, sum, length - sum)</code></strong> reads as "<strong>Read <code>fileStream</code> from <code>sum</code> (offset) to <code>length - sum</code> (total bytes to read) into <code>buffer</code></strong>". OK so at the start, when <code>sum</code> = 0, I will effectively read the whole fileStream into buffer in 1 short, but I think this is not the case. Maybe <code>Read()</code> reads whatever it possibly can into buffer? then returns so that you can <code>Read()</code> it again? I am a little confused. </p>