C # properties in base classes

I have a strange problem that I could not solve. When I try to compile the following snapshot, I get this error:

'AbstractClass' does not implement the 'Property' interface element (compiler error CS0535)

The online help tells me how to make an abstract abstraction of AbstractClass. Can someone tell me where I was wrong?

Cheers rudiger

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"; } } } 
+6
c # properties interface abstract
source share
7 answers

Your AbstractClass should provide an implementation for Property from the IBase interface, even if it's just abstract:

 public abstract class AbstractClass : IBase { public override string ToString() { return "I am abstract"; } public abstract string Property { get; } } 

Update: Luke is right that a particular implementation will have to indicate that Property is an override, otherwise you will get the error "does not implement the inherited abstract element":

 public class ConcreteClass : AbstractClass { public override string Property { get { return "I am Concrete"; } } } 
+19
source share

You must add an abstract property implementation to your AbstractClass:

 public abstract class AbstractClass : IBase { public override string ToString() { return "I am abstract"; } public abstract string Property { get; } } 

And the override keyword for the Concrete class

+3
source share

AbstractClass must implement an IBase that contains a Property, and you have not implemented it

+2
source share

You, an abstract class, do not implement the IBase interface. Just add the Property property to AbstractClass .

 public abstract String Property { get; } 
+2
source share

You need to declare Property in AbstractClass so that it IBase contract.

If you want ConcreteClass to override Property , you must declare it as abstract or virtual . Then you need to declare the implementation of the ConcreteClass Property with override .

  public interface IBase { string Property { get; } } public abstract class AbstractClass : IBase { public abstract string Property { get; } public override string ToString() { return "I am abstract"; } } public class ConcreteClass : AbstractClass { public override string Property { get { return "I am Concrete"; } } } 
+2
source share

You need to implement the IBase -property Property as follows:

 public abstract class AbstractClass : IBase { public override string Property() { return "This is the base-class implementation"; } } 

Or make it abstract .

+1
source share

You must implement the Property property in an abstract class.

+1
source share

All Articles