BufferedStream.Write(Byte[], Int32, Int32) Method
Definition
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.
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)
Parameters
- array
- 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,
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"))