Question Inheritance : derived class doesn't inherit lists

johnss

New member
Joined
May 11, 2020
Messages
4
Programming Experience
Beginner
I have two classes, one that inherits from the other. The derived class is like this:

C#:
    public class AppStateData : GlobalFilterModel
    {
        public AppStateData() : base(4)
        {

        }

        public AppStateData(int nfilters) : base(nfilters)
        {

        }
    }

And the base class, which have a list, is like this:
C#:
    public class GlobalFilterModel
    {
        public EntryState state { get; set; }
        public List<FilterModel> FilterInfo { get; set; }

        public GlobalFilterModel()
        {
            
        }
        public GlobalFilterModel(int n)
        {
            List<FilterModel> FilterInfo = new List<FilterModel>();

            for (int i = 0; i < n; i++)
                FilterInfo.Add(new FilterModel());
        }
    }

Now, when I do
C#:
new AppStateData()
, the property
C#:
FilterInfo
is
C#:
null
.
What am I doing wrong?

I verified that the correct constructor of the base class is called, although, it seems that the derived class doesn´t inherit the list from the base class.
 
public GlobalFilterModel(int n)
{
List<FilterModel> FilterInfo = new List<FilterModel>();
Here you are introducing a new local variable named FilterInfo, instead of assigning to property with same name.
 
Back
Top Bottom