I have a strange problem that I could not solve. When I try to compile the following snipped I get this error:
'AbstractClass' does not implement interface member 'Property' (Compiler Error CS0535)
The online help tells me to make my AbstractClass abstract, which it is. Can anybody tell me where I went wrong?
Cheers Rüdiger
public interface IBase {
string Property { get; }
}
public abstract class AbstractClass : IBase
{
public override string ToString()
{
return "I am abstract";
}
}
public class ConcreteClass : AbstractClass
{
string Property {
get {
return "I am Concrete";
}
}
}
Your AbstractClass
needs to provide an implementation for Property
from the IBase
interface, even if it's just abstract itself:
public abstract class AbstractClass : IBase
{
public override string ToString()
{
return "I am abstract";
}
public abstract string Property { get; }
}
Update: Luke is correct that the concrete implementation will need to specify that Property
is an override, otherwise you'll get a "does not implement inherited abstract member" error:
public class ConcreteClass : AbstractClass
{
public override string Property {
get {
return "I am Concrete";
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With