Is SqlCommand.Dispose() required if associated SqlConnection will be disposed?
问题 I usually use code like this: using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings[\"MyConn\"].ConnectionString)) { var command = connection.CreateCommand(); command.CommandText = \"...\"; connection.Open(); command.ExecuteNonQuery(); } Will my command automatically disposed? Or not and I have to wrap it into using block? Is it required to dispose SqlCommand ? 回答1: Just do this: using(var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConn