Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the length of written bytes with BinaryWriter?

Considering a simple BinaryWriter procedure:

using (BinaryWriter writer = new BinaryWriter(File.Open(fileName, FileMode.Create)))
{
    writer.Write(10000);
    writer.Write("Temp");
    writer.Write(30);
    writer.Write(50.6);
}

How can I get the total number of bytes written by the BinaryWriter? And how can I append this amount to the current writer object, e.g. writer.Write(totalNumberAsBytes)

like image 360
Pythonic Avatar asked Oct 19 '25 12:10

Pythonic


1 Answers

Have you tried writer.BaseStream.Length? This should be the amount of bytes in the stream.

like image 111
Max Play Avatar answered Oct 21 '25 02:10

Max Play



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!