Pythonic
Pythonic

Reputation: 69

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)

Upvotes: 4

Views: 1401

Answers (1)

Max Play
Max Play

Reputation: 4037

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

Upvotes: 5

Related Questions