Click to See Complete Forum and Search --> : Should I use a Using block?


CreganTur
January 6th, 2010, 07:37 AM
I've got a program that loops through hundreds of records. In many cases a Stream will write out some data from each record. Which is optimal: declare my stream object outside the Loop, call its methods within the loop, and then Close() the stream after the loop ends, or is it better to place a Using block within the loop?

I question this because it seems to me that it would be more taxing for my program to constantly initialize and release this object within the loop.

What do you guys think?

boudino
January 6th, 2010, 09:29 AM
I would use using block outside the loop.

dannystommen
January 6th, 2010, 10:31 AM
If every record is independent from each other, do like Boudino mentioned and reuse the Stream object instead of create a new one for every record