Question

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 ?

Was it helpful?

Solution

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

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top