|
-
January 6th, 2010, 08:37 AM
#1
Should I use a Using block?
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?
-
January 6th, 2010, 10:29 AM
#2
Re: Should I use a Using block?
I would use using block outside the loop.
- Make it run.
- Make it right.
- Make it fast.
Don't hesitate to rate my post. 
-
January 6th, 2010, 11:31 AM
#3
Re: Should I use a Using block?
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|