c# - 使用语句和关闭方法

标签 c# .net

与数据库连接对象一起使用时,using 语句是否真的调用了 close 方法? The MSDN documentation说它确保调用 Dispose 方法但没有提到关闭。我在 Stack Overflow 上看到有人说它可以同时做到这两点。是否有人从 Microsoft 或其他确凿的证据中以某种方式给出了具体的答案?

最佳答案

这是 SqlConnection 类的“Dispose”方法:

protected override void Dispose(bool disposing)
{
    if (disposing)
    {
        this._userConnectionOptions = null;
        this._poolGroup = null;
        this.Close();
    }
    this.DisposeMe(disposing);
    base.Dispose(disposing);
}

如你所见,它确实调用了 Close()

关于c# - 使用语句和关闭方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/708213/

相关文章:

.net - 反汇编.NET IL以查找错误消息

.net - iPhone 上是单声道吗?

c# - 输入的原始命令行

c# - 二十一点纸牌、字符串或整数的数组?

c# - 基本 : Where to initialize/set the function

c# - HTTP 请求重新启动 Internet 连接

c# - 方法的执行时间在增加,为什么会这样?

C# Xml 到 Linq 删除一个项目

C# 反射 - 对象与目标类型不匹配

c# - 有没有办法让 using 语句带有动态创建的目标?