title: Stream.Read: EOF vs 0 count
body: <p>The <a href="https://docs.microsoft.com/en-us/dotnet/api/system.io.stream.read?view=netcore-2.0#System_IO_Stream_Read_System_Byte___System_Int32_System_Int32_" rel="nofollow noreferrer">documentation for <code>Stream.Read</code></a> says that:</p>
  
  <blockquote>
    <p>Read returns 0 <strong>only</strong> when there is no more data in the stream <strong>and</strong> no more is expected (such as a closed socket or end of file)</p>
  </blockquote>
  
  <p>From here, it is clear that <code>Read</code> should not return 0 even if 0 is passed to <code>count</code> parameter.</p>
  
  <p>But I tested this with <code>MemoryStream</code> and it returns 0:</p>
  
  <pre><code>var mem = new MemoryStream(new byte[] {1, 2, 3, 4});
  var buf = new byte[0];
  var ret = mem.Read(buf, 0, buf.Length);
  Console.WriteLine(ret); // prints 0
  </code></pre>
  
  <p>Does that mean the documentation is missing something?<br>
  Can an implementation throw an exception if <code>count</code> is 0?</p>