本文介绍了'object'不包含'Dispose'的定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下代码来处理对象..



protected void Dispose(bool disposing)

{

if(disposing)

{if(components!= null)

{components.Dispose(); }

}

base.Dispose(disposing); }



但我收到错误



''对象''不包含定义''Dispose''

I am trying to use the following code to dispose the objects..

protected void Dispose( bool disposing )
{
if( disposing )
{ if(components != null)
{ components.Dispose(); }
}
base.Dispose( disposing ); }

but i am getting the error

''object'' does not contain a definition for ''Dispose''

推荐答案

base.Dispose( disposing );



by


by

IDisposable disposable = base as IDisposable;
if (disposable != null)
{
    disposable.Dispose(disposing);
}



如果 base 类没有实现 IDisposable 一次性对象将为null - 请勿在此处调用 Dispose

你班上的方法应该是 public public virtual public覆盖,不仅 protected


In case that your base class does not implement IDisposable, the disposable object will be null - do not call Dispose here.
And the method in your class should be public or public virtual or public override, not only protected.



这篇关于'object'不包含'Dispose'的定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 13:19