CSharp - Implementing Interface Members Virtually


An implicitly implemented interface member is sealed by default.

It must be marked virtual or abstract in the base class to be overridden.

For example:

interface Printable { void Print(); }

class PDFDocument : Printable
       public virtual void Print() => Console.WriteLine ("PDFDocument.Print");

class RichPDFDocument : PDFDocument
       public override void Print() => Console.WriteLine ("RichPDFDocument.Print");

Calling the interface member through either the base class or the interface calls the subclass's implementation:

RichPDFDocument r = new RichPDFDocument();
r.Print();                          // RichPDFDocument.Print
((Printable)r).Print();             // RichPDFDocument.Print
((PDFDocument)r).Print();               // RichPDFDocument.Print

An explicitly implemented interface member cannot be marked virtual.

And it cannot be overridden. But it can be reimplemented.