-4

为什么我可以在 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()
                    }                        
                }
            }
4

1 回答 1

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
}
于 2013-08-23T14:18:53.497 回答