Let's say I have an abstract class called StuffBase
with an abstract property of type IEnumerable
:
abstract class StuffBase
{
public abstract IEnumerable SomeStuff { get; set; }
}
Now, is it possible to define a derived class that overrides the SomeStuff
property with a derived type, like, for instance:
class StuffDerived : StuffBase
{
public override IEnumerable<int> SomeStuff { get; set; }
}
The idea is that IEnumerable<int>
is derived from IEnumerable
. Is there any way to achieve something like this? When I currently try this, it gives me the error "StuffDerived does not implement abstract member StuffBase.SomeStuff.Set".
But here's what I don't quite get: If the abstract class only defines a getter, but not a setter, then it works. For instance, if SomeStuff
is defined as
public abstract IEnumerable SomeStuff { get; }
and
public override IEnumerable<int> SomeStuff { get; }
it works perfectly fine. An explanation for this would also be nice.