Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
Hi,

I have an abstract class like:

abstract class MyAbstractClass {
   public abstract String Name {get;}

   public void doBasicFunktion(){
      //Do Something
   }
}


Now I want to implement the abstract class but have an additional private set for the property.

class MyClass: MyAbstractClass {
    public override String Name { get; private set;}
}


In this case the compiler say there is no set-accessor that can be override. In case I use the new keyword instead of override the compiler say that Name.get is not implemented.

How can I do such an inheritance.
Posted

But in MyClass you have { get; private set;} but there is only a get property defined.

http://msdn.microsoft.com/en-us/library/yd3z1377.aspx[^]

Good luck!
 
Share this answer
 
Comments
DanielWehrle 8-Nov-10 10:53am    
Yes, because set should be private and:
public abstract String Name { get; private set; }
is not allowed for MyAbstractClass
In inheritance,if your base class is abstract,and that contains some abstract members,then all the abstract members must be overrided in derived class,but you are not allowed to change the signature of the abstract members in derived class
 
Share this answer
 
v2
Comments
Yusuf 14-Mar-11 10:53am    
Removed pre tags
Sajid Ahmed Shahsroha 19-Mar-11 7:56am    
whoever downvoted me plz could you tell me why ?? so that i can improve myself

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900