Muokkaa

Jaa


BufferedStream.Write Method

Definition

Overloads

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)

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

Write(ReadOnlySpan<Byte>)

Source:
BufferedStream.cs
Source:
BufferedStream.cs
Source:
BufferedStream.cs

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.

Applies to

Write(Byte[], Int32, Int32)

Source:
BufferedStream.cs
Source:
BufferedStream.cs
Source:
BufferedStream.cs

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

Parameters

arraybuffer
Byte[]

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

offset
Int32

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

count
Int32

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

Exceptions

Length of array minus offset is less than count.

array is null.

offset or count is negative.

The stream is closed or null.

The stream does not support writing.

Methods were called after the stream was closed.

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.
printfn "Sending data using BufferedStream."
let startTime = DateTime.Now
for _ = 0 to numberOfLoops - 1 do
    bufStream.Write(dataToSend, 0, dataToSend.Length)
bufStream.Flush()
let bufferedTime = (DateTime.Now - startTime).TotalSeconds
printfn $"{numberOfLoops * dataToSend.Length} bytes sent in {bufferedTime:F1} seconds.\n"
' 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