3

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'

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Amir
  • 57
  • 1
  • 9

1 Answers1

7

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.)

Glorfindel
  • 21,988
  • 13
  • 81
  • 109