R
R.A.M.
Hello,
(Sorry for my English...)
I am learning C# and I have a question:
is it good practice to use "using", for example:
using (SqlConnection connection = new SqlConnection(ConnectionString))
{
connection.Open();
...
connection.Close();
}
It could be also written:
SqlConnection connection;
try
{
connection = new SqlConnection(ConnectionString);
connection.Open();
...
}
catch (Exception ex)
{
...
}
finally
{
connection.Close();
}
What are advanatges and disadvantages of each of these methods?
Thank you very much.
/RAM/
(Sorry for my English...)
I am learning C# and I have a question:
is it good practice to use "using", for example:
using (SqlConnection connection = new SqlConnection(ConnectionString))
{
connection.Open();
...
connection.Close();
}
It could be also written:
SqlConnection connection;
try
{
connection = new SqlConnection(ConnectionString);
connection.Open();
...
}
catch (Exception ex)
{
...
}
finally
{
connection.Close();
}
What are advanatges and disadvantages of each of these methods?
Thank you very much.
/RAM/