CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2008
    Posts
    144

    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?

  2. #2
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    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.

  3. #3
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    865

    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
  •  





Click Here to Expand Forum to Full Width

Featured