In fact, using a block is equivalent to trying - the final block, which ensures that, finally, it will always be executed, for example.
using (SqlConnection con = new SqlConnection(ConnectionString)) { using (SqlCommand cmd = new SqlCommand("Command", con)) { con.Open(); cmd.ExecuteNonQuery(); } }
Equality
SqlConnection con = null; SqlCommand cmd = null; try { con = new SqlConnection(ConnectionString); cmd = new SqlCommand("Command", con); con.Open(); cmd.ExecuteNonQuery(); } finally { if (null != cmd); cmd.Dispose(); if (null != con) con.Dispose(); }
Azhar
source share