BinaryWriter's Close method

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is it necessary to call the close method for every BinaryWriter that I
create? Or is it just a way to close the underlying stream? For example is it
OK to do the following:

private void WriteUnicodeStringToStream (Stream s, string string)
{
BinaryWriter bw = new BinaryWriter (s, Encoding.Unicode);
bw.Write (string);
}

As you can see, I don't close the BinaryWriter since I haven't necessarily
done the stream. Is it OK to do this?

As far as I can see, the Close method for a BinaryWriter doesn't do anything
than close the stream, so I assume it is safe... right?
 
If you do not close the binary writer then underlying stream will be open.
If close called on writer the stream will also be closed. check the MSDN
documentation.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top