Question: I've seen [this code sample](https://stackoverflow.com/a/5654324/859154) which - reads from a Stream into a buffer : 

```
byte[] buffer = new byte[1024 * 32];
int bytesRead;

while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0)
{
    //...
}

```

But looking at the second parameter of `stream.Read(..,0,..)` which is the *[zero-based byte offset in **buffer** at which to begin storing the data read from the current stream](http://msdn.microsoft.com/en-us/library/system.io.stream.read(v=vs.110).aspx).*

So is the offset is 0 each time ? who said it doesn't overwrite data at those indexes? 

On the contrary : I also saw [this example](https://stackoverflow.com/a/9571057/859154) : 

```
 int read, offset = 0;
     while(count > 0 && (read = source.Read(buffer, offset, count)) > 0) {
        offset += read;
        count -= read;
    }

```

So here the offset is offsetted after each reading ( which seems more logical to me)

But I must be missing something : 

Was my observation was right? When should I use each case ?

NB , my pov is network stream : sending file.

Answer: 
You've missed an important part of that original answer:

```
byte[] buffer = new byte[1024 * 32];
int bytesRead;

while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0)
{
    // Use the data you've read
}

```

You use the data that you've read into the buffer so it can then be thrown away (replaced). This is useful if you've got a potentially big stream and don't want to suffer from memory issues.

In your 2nd example you'll be able to read the entire contents of the stream into a buffer and deal with the contents as a whole.
The two samples is right.I read [the link code](https://stackoverflow.com/questions/5654298/filestream-read-write-methods-limitation/5654324#5654324).

```
while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0)
{
    // Use the data you've read once you have received,and then thow it away.
    //So,you can cover the old data.
}

while(count > 0 && (read = source.Read(buffer, offset, count)) > 0) {
    offset += read;
    count -= read;
    //received all data from the stream,and then use them.
    //So you can't cover the old data.
}

```

Two methods are available.