title: Why must I use Dispose()?
body: <p>Here is my code:</p>
  
  <pre><code>public void InsertData()
  {
      using (SqlConnection connection = new SqlConnection(DBHelper.ConnectionString))
      {
          using (SqlCommand command = new SqlCommand("Some Simple Insert Query", connection))
          {
              connection.Open();
              command.ExecuteNonQuery();
          }
      }
  }
  </code></pre>
  
  <p>But I found this code sample:</p>
  
  <pre><code>public void InsertData()
  {
      SqlConnection connection = new SqlConnection(DBHelper.ConnectionString);
      connection.Open();
      SqlCommand command = new SqlCommand("Some Simple Insert Query", connection);
      command.ExecuteNonQuery();
  
      command.Dispose();
      connection.Close();
      connection.Dispose();
  }
  </code></pre>
  
  <p>why does the author use</p>
  
  <blockquote>
    <p>command.Dispose()</p>
  </blockquote>
  
  <p>and  </p>
  
  <blockquote>
    <p>connection.Dispose();</p>
  </blockquote>
  
  <p>in their code?</p>