using (SqlConnection conn = new SqlConnection(source))
            {
                // open the connoction
                conn.Open();
                // Do something usefu△
                // Close it myself
                conn.Close();
            }

  因为using子句将确保在任何情况下都执行关闭操作。但是,应确保像这样的任何资源尽可能早地释放。因为在块的其余部分可能有更多的代码,而没有必要锁定资源。

相关文章:

  • 2021-09-10
  • 2021-09-16
  • 2022-01-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-26
  • 2021-06-24
  • 2021-10-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案