472,142 Members | 1,046 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,142 software developers and data experts.

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 2230
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 leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.