Explicit interface implementation cannot be virtual

后端 未结 5 1738
遥遥无期
遥遥无期 2021-02-05 13:20

For the record, I\'ve already seen this connect item but I can\'t really understand what would be the problem in supporting this.

Say I have the following code:

5条回答
  •  长情又很酷
    2021-02-05 13:26

    Being able to have explicit interface implementations be virtual would be useful in only one scenario: when a derived-class override needs to call the parent-class implementation. Unfortunately, even if explicit interface implementations could be made virtual, there wouldn't be any way for an overriding class to call its parent's implementation absent some new syntax for doing so. VB.net handles this nicely by allowing a method which implements an interface to be declared Protected with a different name from the interface's method. A derived class can thus override the Protected method (using the appropriate name), and that override can call the parent-class version (using the same name).

提交回复
热议问题