R
R.A.M.
Hello,
I have started larning C# and I have a question concerning "using
(...)" keyword.
For example:
using (SqlConnection connection = new SqlConnection(ConnectionString))
{
connection.Open();
....
connection.Close();
}
I can write it also this way:
SqlConnection connection;
try
{
connection = new SqlConnection(ConnectionString));
connection.Open();
....
connection.Close();
}
catch (...)
{
....
}
finally
{
....
}
But it won't dispose 'connection'.
Which solution is better? What are adventages and disadventages?
Thank you very much
/RAM/
I have started larning C# and I have a question concerning "using
(...)" keyword.
For example:
using (SqlConnection connection = new SqlConnection(ConnectionString))
{
connection.Open();
....
connection.Close();
}
I can write it also this way:
SqlConnection connection;
try
{
connection = new SqlConnection(ConnectionString));
connection.Open();
....
connection.Close();
}
catch (...)
{
....
}
finally
{
....
}
But it won't dispose 'connection'.
Which solution is better? What are adventages and disadventages?
Thank you very much
/RAM/