什么是“进入布置的封闭”这里是什么意思? [英] What does "access to disposed closure" mean here?

查看:328
本文介绍了什么是“进入布置的封闭”这里是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么Resharper在下面的代码示例中警告我有关布置闭包的访问:

Why does Resharper warn me about "access to disposed closure" in the following code sample:

using (SqlCommand command = new SqlCommand())
{
    command.Parameters.Add("@temp", SqlDbType.VarChar);
    Action<string> action = str =>
        {
            command.Parameters["@temp"].Value = string.Empty;
        };
}



我不使用 code> statement ...如何解决这个问题?

I don't use delegate outside using statement... How to fix this?

推荐答案

/ code>在中,可以在中使用 action 使用参考来处理命令

You are referencing command in action, you can use action in somewhere else then in using and reference to disposed command.

Resharper告诉你,你可以访问布置闭包,因为使用之外的操作使用会导致。避免使用一次性对象,当然会抛出 NullReferenceException ,但很难找到真正的问题。

Resharper is telling you that you can access to disposed closure, because using action outside using will cause that. Avoid using disposable object like that, of course it will throw NullReferenceException, but it can be difficult to find the real problem.

这篇关于什么是“进入布置的封闭”这里是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆