Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How add virtual property to sealed class

I wrote a class in c# which inherits TextBox and now I want to add a virtual property to it:

    public virtual Color WatermarkColor
    {
        private get { return _watermarkColor; }
        set
        {
            _watermarkColor = value;
            OnEnter(null);
            OnLeave(null);
        }
    }

but this error occurred:

Error 1 'xXx.TextBoxPlus.WaterMark.get' is a new virtual member in sealed class 'xXx.TextBoxPlus'

like image 259
Amir Avatar asked Oct 21 '25 08:10

Amir


1 Answers

You have declared TextBoxPlus as a sealed class, so it can't be subclassed. Therefore, the virtual specifier is unnecessary because it will never be overridden.

Just remove the virtual and you should be fine. (Or remove the sealed from the class definition if you intend to subclass it later.)

like image 59
Glorfindel Avatar answered Oct 22 '25 23:10

Glorfindel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!