'C# how to correctly override base class property in children class?

Could somebody tell me please, how in children class correctly override property declared in parent class? I am trying to override "Tasks" property. In child class it should return list of items of type "ICheckListTask".Part of code:

Parent class:

internal class CBaseTaskList : IBaseTaskList
{
    protected List<IBaseTask> _tasks = new List<IBaseTask>();

    virtual protected List<IBaseTask> Tasks
    {
        get { return _tasks; }
        set { _tasks = value; }
    }

    public virtual IBaseTask this[int index]
    {
        get { return Tasks[index]; }
        set { Tasks[index] = value; }
    }

    public virtual void Add(IBaseTask newTask)
    {
        Tasks.Add(newTask);
    }

Children class:

internal class CCheckListTaskList : CBaseTaskList, ICheckListTaskList
{
    override protected List<ICheckListTask> Tasks
    {
        get { return (List<ICheckListTask>)_tasks; }
        set { Tasks = value; }
    }

    public void WhereIsDone()
    {
        Tasks = new List<ICheckListTask>(Tasks.Where(x => x.IsDone == true));
    }

In children class I get error what type of CCheckListTaskList.Task must be not "List<ICheckListTask>", but "List<IBaseTask>". How to correctly do what I want to do?



Solution 1:[1]

I think you should use "new" instead of "override"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 teder.ted