为什么我可以访问Bmw getter setter方法中的dispose方法而不是dispose()方法?
我如何处理以下字段:?
Class Car: IDisposable
{
private FontWeight bmw;
public FontWeight Bmw
{
bmw.Dispose(); <<<<<<<< Can access Dispose
get
{ return bmw; }
set
{ bmw= value;
}
public void Dispose(){
bmw.Dispose(); <<<< Cant access Dispose()
}
}
}
答案 0 :(得分:2)
如果这是您的代码,那么您内部会遇到大量语法错误:
public FontWeight Bmw
{
/// here shouldn't be any code, just getters and setters
get { return bmw; }
set { bmw = value; }
/// you forgot to close the property here
} /// now it's closed
public void Dispose()
{
bmw.Dispose(); /// now it will work
}