2012-08-25 63 views
0

我有被導出,所以我有幾個int和string汽車性能C#Autoproperties和字典

// base class 

    public virtual int MyVariable {get; set; }; 


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

    } 

我怎樣才能做一個解釋同一個基本情況?

回答

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; } 

}