0

我有一个派生的基本案例,所以我几乎没有 int 和 string Auto 属性

// base class 

   public virtual int MyVariable {get; set; }; 


// Derived class
    private int myVariable = 0;
    public override int MyVariable 
    {
        get { return myVariable ; }
        set { myVariable = value; }

    }

我怎样才能对字典做同样的事情?

4

1 回答 1

2

它几乎相同,尽管您当然需要将类型从更改int为您的字典类型。

示例Dictionary<string,int>

基类:

public virtual Dictionary<string,int> MyVariable {get; set; }; 

派生类:

private Dictionary<string,int> myVariable = new Dictionary<string,int>();
public override Dictionary<string,int> MyVariable 
{
    get { return myVariable ; }
    set { myVariable = value; }

}
于 2012-08-25T19:16:54.937 回答