BufferedStream.Write BufferedStream.Write BufferedStream.Write BufferedStream.Write Method

Definition

Overloads

Write(ReadOnlySpan<Byte>) Write(ReadOnlySpan<Byte>) Write(ReadOnlySpan<Byte>) Write(ReadOnlySpan<Byte>)

Writes a sequence of bytes to the current buffered stream and advances the current position within this buffered stream by the number of bytes written.

Write(Byte[], Int32, Int32) Write(Byte[], Int32, Int32) Write(Byte[], Int32, Int32) Write(Byte[], Int32, Int32)

Copies bytes to the buffered stream and advances the current position within the buffered stream by the number of bytes written.

Write(ReadOnlySpan<Byte>) Write(ReadOnlySpan<Byte>) Write(ReadOnlySpan<Byte>) Write(ReadOnlySpan<Byte>)

Writes a sequence of bytes to the current buffered stream and advances the current position within this buffered stream by the number of bytes written.

public:
 override void Write(ReadOnlySpan<System::Byte> buffer);
public override void Write (ReadOnlySpan<byte> buffer);
override this.Write : ReadOnlySpan<byte> -> unit
Public Overrides Sub Write (buffer As ReadOnlySpan(Of Byte))

Parameters

buffer
ReadOnlySpan<Byte>

A region of memory. This method copies the contents of this region to the current buffered stream.

Remarks

Use the CanWrite property to determine whether the current instance supports writing. Use the WriteAsync method to write asynchronously to the current buffered stream.

If the write operation is successful, the position within the buffered stream advances by the number of bytes written. If an exception occurs, the position within the buffered stream remains unchanged.

Write(Byte[], Int32, Int32) Write(Byte[], Int32, Int32) Write(Byte[], Int32, Int32) Write(Byte[], Int32, Int32)

Copies bytes to the buffered stream and advances the current position within the buffered stream by the number of bytes written.

public:
 override void Write(cli::array <System::Byte> ^ array, int offset, int count);
public override void Write (byte[] array, int offset, int count);
override this.Write : byte[] * int * int -> unit
Public Overrides Sub Write (array As Byte(), offset As Integer, count As Integer)

Parameters

array
Byte[]

The byte array from which to copy count bytes to the current buffered stream.

offset
Int32 Int32 Int32 Int32

The offset in the buffer at which to begin copying bytes to the current buffered stream.

count
Int32 Int32 Int32 Int32

The number of bytes to be written to the current buffered stream.

Exceptions

Length of array minus offset is less than count.

The stream is closed or null.

Examples

This code example is part of a larger example provided for the BufferedStream class.

// Send the data using the BufferedStream.
Console::WriteLine( "Sending data using BufferedStream." );
startTime = DateTime::Now;
for ( int i = 0; i < numberOfLoops; i++ )
{
   bufStream->Write( dataToSend, 0, dataToSend->Length );

}
bufStream->Flush();
bufferedTime = (DateTime::Now - startTime).TotalSeconds;
Console::WriteLine( "{0} bytes sent in {1} seconds.\n", (numberOfLoops * dataToSend->Length).ToString(), bufferedTime.ToString(  "F1" ) );

// Send the data using the BufferedStream.
Console.WriteLine("Sending data using BufferedStream.");
startTime = DateTime.Now;
for(int i = 0; i < numberOfLoops; i++)
{
    bufStream.Write(dataToSend, 0, dataToSend.Length);
}
bufStream.Flush();
bufferedTime = (DateTime.Now - startTime).TotalSeconds;
Console.WriteLine("{0} bytes sent in {1} seconds.\n",
    numberOfLoops * dataToSend.Length,
    bufferedTime.ToString("F1"));
' Send the data using the BufferedStream.
Console.WriteLine("Sending data using BufferedStream.")
startTime = DateTime.Now
For i As Integer = 1 To numberOfLoops
    bufStream.Write(dataToSend, 0, dataToSend.Length)
Next i

bufStream.Flush()
bufferedTime = DateTime.Now.Subtract(startTime).TotalSeconds
Console.WriteLine("{0} bytes sent In {1} seconds." & vbCrLf, _
    numberOfLoops * dataToSend.Length, _
    bufferedTime.ToString("F1"))
See also

Applies to