The fields in this class and its base are not encapsulated properly for performance reasons. See ReadBuffer for more information.
A frequent use case for this class is when a not previously known number of bytes need to be written to a stream one by one. In this case the following code tends to be much faster than calling Stream.WriteByte for each byte: void WriteToStream(Stream stream) { var writeBuffer = new WriteBuffer(stream.Write, 1024); bool done = false; while (!done && ((writeBuffer.Count < writeBuffer.Capacity) || writeBuffer.Flush())) { // .. byte theByte = 0x00; // Calculate the byte to append to the buffer writeBuffer[writeBuffer.Count++] = theByte; // Set done to true as soon as we're done... } }