Is it possible to do something like this?
class A { public virtual string prop { get { return 'A'; } } } class B: A { private string X; public override string prop { get { return X; } set { X = value; } } }
That is, the base class provides a virtual property with only a GET accessor, but the child class overrides the GET and also provides a SET.
The current example doesn’t compile, but perhaps I’m missing something here.
Added: To clarify, no I don’t want to redefine with new. I want to add a new accessor. I know it wasn’t in the base class, so it cannot be overriden. OK, let me try to explain how it would look without the syntactic sugar:
class A { public virtual string get_prop() { return 'A'; } } class B: A { private string X; public override string get_prop() { return X; } public virtual string set_prop() { X = value; } }
No, this is not possible. Unfortunately you can not even override and change the accessor level (from protected to public for example), as documented on MSDN. I would recommend that you consider restructuring the code/class slightly and look for an alternative way to accomplish this task such as declaring the set accessor with the protected modifier using a SetProperty method in the derived class.