什么"获得处置倒闭"这里的意思? [英] What does "access to disposed closure" mean here?

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

问题描述

为什么以下code样品中确实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;
        };
}

我不使用语句外使用代理...如何解决这一问题?

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

推荐答案

您正在引用命令动作,您可以使用动作在别的地方,然后在使用引用到布置命令

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.

这篇关于什么&QUOT;获得处置倒闭&QUOT;这里的意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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