Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>If I call Dispose(), does it call Close()?</p> </blockquote> <p>Calling <a href="http://msdn.microsoft.com/en-us/library/system.idisposable.dispose.aspx" rel="nofollow noreferrer"><code>Dispose</code></a> should take any required actions to dispose of the resource, which should be similar, if not identical to, calling <a href="http://msdn.microsoft.com/en-us/library/system.io.stream.close.aspx" rel="nofollow noreferrer"><code>Close</code></a>. This, however, is an implementation detail and not necessarily guaranteed (though we can expect that the BCL follows this guideline).</p> <blockquote> <p>If I want to use an object (say SqlDataReader), but then use it again in another code block, should I not call Dispose()? Which also means to omit the using statement.</p> </blockquote> <p>If you want to use the object again, you definitely should not dispose it. However, you should typically use two separate connections if you're going to the database two separate times. It's generally not a good idea to keep an <a href="http://msdn.microsoft.com/en-us/library/system.data.idatareader.aspx" rel="nofollow noreferrer">IDataReader</a> around an longer than is needed to grab your needed data.</p> <blockquote> <p>Also, to clarify, if a FileStream is wrapping a StreamWriter and I call dispose on the FileStream, this will call Flush(), Close() and Dispose() (depending on whether Dispose() calls Close()) on the StreamWriter, right? Likewise, if I call Close on the FileStream, this will only call Flush() and Close() on the FileStream.</p> </blockquote> <p>Disposing an object that wraps another disposable object should call <code>Dispose</code> on the interior object. Calling <code>Close</code> on a <code>FileStream</code> will call its <code>Dispose</code> method under the good, so it will also act on both streams.</p> <blockquote> <p>Is checking IL a good way to answer these questions about what is happening under the hood?</p> </blockquote> <p>Checking IL will definitely answer most of these questions definitively. As <a href="https://stackoverflow.com/questions/667111/some-advanced-questions-on-the-using-statement/667123#667123">@Rich</a> says, you can also just try debugging your own Dispose implementations. There is also, of course, MSDN documentation to start with before you try to figure it out yourself, and Reflector if you don't want to muck around in IL.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload