Ask Learn
Preview
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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. |
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))
A region of memory. This method copies the contents of this region to the current buffered stream.
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.
Product | Versions |
---|---|
.NET | Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
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> ^ buffer, int offset, int count);
public:
override void Write(cli::array <System::Byte> ^ array, int offset, int count);
public override void Write(byte[] buffer, int offset, int count);
public override void Write(byte[] array, int offset, int count);
override this.Write : byte[] * int * int -> unit
override this.Write : byte[] * int * int -> unit
Public Overrides Sub Write (buffer As Byte(), offset As Integer, count As Integer)
Public Overrides Sub Write (array As Byte(), offset As Integer, count As Integer)
The offset in the buffer at which to begin copying bytes to the current buffered stream.
The number of bytes to be written to the current buffered stream.
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.
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,
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"))
Product | Versions |
---|---|
.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 |
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign in