Difference in declaring IDisposable member in using block or at using block declaration?
Posted
by dotnetdev
on Stack Overflow
See other posts from Stack Overflow
or by dotnetdev
Published on 2010-03-24T21:18:53Z
Indexed on
2010/03/24
21:23 UTC
Read the original article
Hit count: 171
c#
Hi,
I have the code below:
using (SqlCommand command = new SqlCommand())
{
command.CommandType = System.Data.CommandType.StoredProcedure;
command.Connection = new SqlConnection();
command.CommandText = "";
command.Parameters.Add(new SqlParameter("@ExperienceLevel", 3).Direction = System.Data.ParameterDirection.Input);
SqlDataReader dataReader = command.ExecuteReader();
}
Is there any functional impact in declaring the SqlConnection where I currently am declaring it as opposed to like so?:
using (SqlCommand command = new SqlCommand())
using (SqlConnection connection = new SqlConnection())
Thanks
© Stack Overflow or respective owner