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

定義

多載

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))

參數

buffer
ReadOnlySpan<Byte>

記憶體區域。A region of memory. 這個方法會將此區域內容複製到目前的緩衝資料流。This method copies the contents of this region to the current buffered stream.

備註

CanWrite使用屬性來判斷目前的實例是否支援寫入。Use the CanWrite property to determine whether the current instance supports writing. WriteAsync使用方法, 以非同步方式寫入目前緩衝的資料流程。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)

參數

array
Byte[]

用於複製 count 位元組至目前緩衝資料流的位元組陣列。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.

例外狀況

array 長度減 offset 小於 countLength of array minus offset is less than count.

資料流已關閉或為 nullThe stream is closed or null.

資料流不支援寫入。The stream does not support writing.

關閉資料流後呼叫了方法。Methods were called after the stream was closed.

範例

這個程式碼範例是針對BufferedStream類別提供之較大範例的一部分。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"))
另請參閱

適用於