Прочетете на английски Редактиране

Споделяне чрез


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.

C#
public override void Write(ReadOnlySpan<byte> buffer);

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

.NET 10 и други версии
Продукт Версии
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10

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.

C#
public override void Write(byte[] buffer, int offset, int count);
C#
public override void Write(byte[] array, int offset, int count);

Parameters

bufferarray
Byte[]
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.

C#
// 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"));

See also

Applies to

.NET 10 и други версии
Продукт Версии
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.5, 1.6, 2.0, 2.1