I've just encounter this problem. As far as I know, isn't "str1" supposed to be a local variable and I'm able to create a new variable with the same name outside of the using code block?
Of course I can create a variable with a different name and move on but this really bother me. Can someone explain this?
public int Execute(string sql, params SqlParameter[] parameters)
{
try
{
this.AddSql(sql, parameters);
using (var cmd = new SqlCommand(sql, this.connection))
{
var str1 = "";
}
//var str1 =""; // error because variable str1 is used above
//str1 =""; // this also causes an error because "Can not resolve symbol 'str1'"
}
catch (Exception e)
{
//...
}
return 0;
}