문제

I have a base case that gets derived so i have few int and string Auto properties

// base class 

   public virtual int MyVariable {get; set; }; 


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

    }

How can i do the same with a Dictionary ?

도움이 되었습니까?

해결책

It is pretty much the same, though you will of course need to change the type from int to your dictionary type.

Example with a Dictionary<string,int>:

Base class:

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

Derived class:

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

}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top