StreamWriter, FileStream, StreamReader - How to know if they are closed

  • Thread starter Thread starter McFly Racing
  • Start date Start date
M

McFly Racing

I am using a StreamWriter a FileStream and a StreamReader. In the event I
have an error I want to check in my finally block and close these if they
are not already closed. How will I know if they are already closed before
trying to close them again? Thank you.
 
Hi McFly Racing,

If you happen to call Close twice, it isn't a problem. However, you should
only close the file stream in the finally block. This is exactly what the
finally block is good for.

Joe
 
Joe Mayo said:
If you happen to call Close twice, it isn't a problem. However, you should
only close the file stream in the finally block. This is exactly what the
finally block is good for.

And if you use the "using" statement, you don't even need to call Close
explicitly at all :)
 
Back
Top