Why can I not add a set accessor to an overriden property?

Posted by Svish on Stack Overflow See other posts from Stack Overflow or by Svish
Published on 2009-08-04T12:26:16Z Indexed on 2010/05/18 2:00 UTC
Read the original article Hit count: 254

Filed under:
|
|
|

In a base class I have this property:

public virtual string Text 
{
    get { return text; }
}

I want to override that and return a different text, but I would also like to be able to set the text, so I did this:

public override string Text
{
    get { return differentText; }
    set { differentText = value; }
}

This however does not work. I get a red squiggly under set saying that I can not override because it does not have a set accessor. Why is this aproblem? What should I do?

© Stack Overflow or respective owner

Related posts about c#

Related posts about inheritance