BufferedStream.Write Metodo

Definizione

Overload

Write(ReadOnlySpan<Byte>)

Scrive una sequenza di byte nel flusso memorizzato nel buffer corrente e sposta in avanti la posizione nel flusso in base al numero di byte scritti.

Write(Byte[], Int32, Int32)

Copia i byte nel flusso memorizzato nel buffer e sposta la posizione corrente, all'interno del flusso memorizzato nel buffer, in base al numero di byte scritto.

Write(ReadOnlySpan<Byte>)

Origine:
BufferedStream.cs
Origine:
BufferedStream.cs
Origine:
BufferedStream.cs

Scrive una sequenza di byte nel flusso memorizzato nel buffer corrente e sposta in avanti la posizione nel flusso in base al numero di byte scritti.

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

Parametri

buffer
ReadOnlySpan<Byte>

Un'area di memoria. Questo metodo copia il contenuto di quest'area nel flusso memorizzato nel buffer corrente.

Commenti

Utilizzare la CanWrite proprietà per determinare se l'istanza corrente supporta la scrittura. Usare il WriteAsync metodo per scrivere in modo asincrono nel flusso memorizzato nel buffer corrente.

Se l'operazione di scrittura ha esito positivo, la posizione all'interno del flusso memorizzato nel buffer avanza in base al numero di byte scritti. Se si verifica un'eccezione, la posizione all'interno del flusso memorizzato nel buffer rimane invariata.

Si applica a

Write(Byte[], Int32, Int32)

Origine:
BufferedStream.cs
Origine:
BufferedStream.cs
Origine:
BufferedStream.cs

Copia i byte nel flusso memorizzato nel buffer e sposta la posizione corrente, all'interno del flusso memorizzato nel buffer, in base al numero di byte scritto.

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)

Parametri

arraybuffer
Byte[]

Matrice di byte da cui copiare i byte di count nel flusso corrente memorizzato nel buffer.

offset
Int32

Offset nel buffer da cui avviare la copia dei byte nel flusso corrente memorizzato nel buffer.

count
Int32

Numero di byte da scrivere nel flusso corrente memorizzato nel buffer.

Eccezioni

La lunghezza di array meno offset è minore di count.

array è null.

offset o count è negativo.

Il flusso è chiuso o null.

Il flusso non supporta la scrittura.

Sono stati chiamati dei metodi dopo la chiusura del flusso.

Esempio

Questo esempio di codice fa parte di un esempio più ampio fornito per la BufferedStream classe .

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

Vedi anche

Si applica a