In the example below, is connection going to close and dispose when exception is thrown if it is within using statement?
using (var conn = new SqlConnection("..."))
{
conn.Open();
// stuff happens here and exception is thrown...
}
I know this code below will make sure that it does, but I'm curious how using statment does it.
var conn;
try
{
conn = new SqlConnection("...");
conn.Open();
// stuff happens here and exception is thrown...
}
// catch it or let it bubble up
finally
{
conn.Dispose();
}