title: With... End With vs Using in VB.NET
body: <p>I just found out that like C#, VB.NET also has the <code>using</code> keyword.</p>
  
  <p>Until now I thought it didn't have it (stupid of me, I know...) and did stuff like this instead:</p>
  
  <pre><code>With New OleDbConnection(MyConnectionString)
     ' Do stuff
  End With
  </code></pre>
  
  <p>What are the implications of this compared to doing it with a <code>using</code> statement like this</p>
  
  <pre><code>Using cn as New OleDBConnection(MyConnectionString)
      With cn
          ' Do stuff with cn
      End With
  End using
  </code></pre>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I should add that I am familiar with what the <code>using</code> statement does in that it disposes of the object when the construct is exited.</p>
  
  <p>However, as far as I understand the <code>With New ...</code> construct will have the object mark the object as ready for garbage collection when it goes out of scope.</p>
  
  <p>So my question really is, is the only difference the fact that with <code>using</code> I will release the memory right away, whereas with the <code>With</code> construct it will be released whenever the GC feels like it? Or am I missing something bigger here?</p>
  
  <p>Are there any best practice implications? Should I go and rewrite all the code with I used <code>With New MyDisposableObject() ... End With</code> as <code>Using o as New MyDisposableObject()</code>?</p>