469,631 Members | 1,776 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,631 developers. It's quick & easy.

BinaryWriter's Close method

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?
Nov 16 '05 #1
1 2155
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.

"Barguast" <It*****************@Email.com> wrote in message
news:CC**********************************@microsof t.com...
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?

Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by ThunderMusic | last post: by
3 posts views Thread by Peyman | last post: by
17 posts views Thread by Filip Strugar | last post: by
1 post views Thread by Claire | last post: by
5 posts views Thread by Travis Llewellyn | last post: by
7 posts views Thread by Peter Morris | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.